@steedos/odata-v4-parser 2.5.3-beta.2 → 2.5.3-beta.21
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/package.json +2 -2
- package/src/json.ts +371 -371
- package/src/nameOrIdentifier.ts +748 -748
- package/src/odataUri.ts +37 -37
- package/src/primitiveLiteral.ts +684 -684
- package/src/resourcePath.ts +461 -461
- package/src/utils.ts +36 -36
package/src/resourcePath.ts
CHANGED
|
@@ -1,461 +1,461 @@
|
|
|
1
|
-
import Utils from "./utils";
|
|
2
|
-
import Lexer from "./lexer";
|
|
3
|
-
import PrimitiveLiteral from "./primitiveLiteral";
|
|
4
|
-
import NameOrIdentifier from "./nameOrIdentifier";
|
|
5
|
-
import Expressions from "./expressions";
|
|
6
|
-
|
|
7
|
-
export namespace ResourcePath {
|
|
8
|
-
export function resourcePath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
9
|
-
if (value[index] === 0x2f) index++;
|
|
10
|
-
let token = ResourcePath.batch(value, index) ||
|
|
11
|
-
ResourcePath.entity(value, index, metadataContext) ||
|
|
12
|
-
ResourcePath.metadata(value, index);
|
|
13
|
-
if (token) return token;
|
|
14
|
-
|
|
15
|
-
let resource = NameOrIdentifier.entitySetName(value, index, metadataContext) ||
|
|
16
|
-
ResourcePath.functionImportCall(value, index, metadataContext) ||
|
|
17
|
-
ResourcePath.crossjoin(value, index) ||
|
|
18
|
-
ResourcePath.all(value, index) ||
|
|
19
|
-
ResourcePath.actionImportCall(value, index, metadataContext) ||
|
|
20
|
-
NameOrIdentifier.singletonEntity(value, index);
|
|
21
|
-
|
|
22
|
-
if (!resource) return;
|
|
23
|
-
let start = index;
|
|
24
|
-
index = resource.next;
|
|
25
|
-
let navigation: Lexer.Token;
|
|
26
|
-
|
|
27
|
-
switch (resource.type) {
|
|
28
|
-
case Lexer.TokenType.EntitySetName:
|
|
29
|
-
navigation = ResourcePath.collectionNavigation(value, resource.next, resource.metadata);
|
|
30
|
-
metadataContext = resource.metadata;
|
|
31
|
-
delete resource.metadata;
|
|
32
|
-
break;
|
|
33
|
-
case Lexer.TokenType.EntityCollectionFunctionImportCall:
|
|
34
|
-
navigation = ResourcePath.collectionNavigation(value, resource.next, resource.value.import.metadata);
|
|
35
|
-
metadataContext = resource.value.import.metadata;
|
|
36
|
-
delete resource.value.import.metadata;
|
|
37
|
-
break;
|
|
38
|
-
case Lexer.TokenType.SingletonEntity:
|
|
39
|
-
navigation = ResourcePath.singleNavigation(value, resource.next, resource.metadata);
|
|
40
|
-
metadataContext = resource.metadata;
|
|
41
|
-
delete resource.metadata;
|
|
42
|
-
break;
|
|
43
|
-
case Lexer.TokenType.EntityFunctionImportCall:
|
|
44
|
-
navigation = ResourcePath.singleNavigation(value, resource.next, resource.value.import.metadata);
|
|
45
|
-
metadataContext = resource.value.import.metadata;
|
|
46
|
-
delete resource.value.import.metadata;
|
|
47
|
-
break;
|
|
48
|
-
case Lexer.TokenType.ComplexCollectionFunctionImportCall:
|
|
49
|
-
case Lexer.TokenType.PrimitiveCollectionFunctionImportCall:
|
|
50
|
-
navigation = ResourcePath.collectionPath(value, resource.next, resource.value.import.metadata);
|
|
51
|
-
metadataContext = resource.value.import.metadata;
|
|
52
|
-
delete resource.value.import.metadata;
|
|
53
|
-
break;
|
|
54
|
-
case Lexer.TokenType.ComplexFunctionImportCall:
|
|
55
|
-
navigation = ResourcePath.complexPath(value, resource.next, resource.value.import.metadata);
|
|
56
|
-
metadataContext = resource.value.import.metadata;
|
|
57
|
-
delete resource.value.import.metadata;
|
|
58
|
-
break;
|
|
59
|
-
case Lexer.TokenType.PrimitiveFunctionImportCall:
|
|
60
|
-
navigation = ResourcePath.singlePath(value, resource.next, resource.value.import.metadata);
|
|
61
|
-
metadataContext = resource.value.import.metadata;
|
|
62
|
-
delete resource.value.import.metadata;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (navigation) index = navigation.next;
|
|
67
|
-
if (value[index] === 0x2f) index++;
|
|
68
|
-
if (resource) return Lexer.tokenize(value, start, index, { resource, navigation }, Lexer.TokenType.ResourcePath, navigation || <any>{ metadata: metadataContext });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function batch(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
72
|
-
if (Utils.equals(value, index, "$batch")) return Lexer.tokenize(value, index, index + 6, "$batch", Lexer.TokenType.Batch);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function entity(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
76
|
-
if (Utils.equals(value, index, "$entity")) {
|
|
77
|
-
let start = index;
|
|
78
|
-
index += 7;
|
|
79
|
-
|
|
80
|
-
let name;
|
|
81
|
-
if (value[index] === 0x2f) {
|
|
82
|
-
name = NameOrIdentifier.qualifiedEntityTypeName(value, index + 1, metadataContext);
|
|
83
|
-
if (!name) return;
|
|
84
|
-
index = name.next;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return Lexer.tokenize(value, start, index, name || "$entity", Lexer.TokenType.Entity);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function metadata(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
92
|
-
if (Utils.equals(value, index, "$metadata")) return Lexer.tokenize(value, index, index + 9, "$metadata", Lexer.TokenType.Metadata);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function collectionNavigation(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
96
|
-
let start = index;
|
|
97
|
-
let name;
|
|
98
|
-
if (value[index] === 0x2f) {
|
|
99
|
-
name = NameOrIdentifier.qualifiedEntityTypeName(value, index + 1, metadataContext);
|
|
100
|
-
if (name) {
|
|
101
|
-
index = name.next;
|
|
102
|
-
metadataContext = name.value.metadata;
|
|
103
|
-
delete name.value.metadata;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
let path = ResourcePath.collectionNavigationPath(value, index, metadataContext);
|
|
108
|
-
if (path) index = path.next;
|
|
109
|
-
|
|
110
|
-
if (!name && !path) return;
|
|
111
|
-
|
|
112
|
-
return Lexer.tokenize(value, start, index, { name, path }, Lexer.TokenType.CollectionNavigation, path || name);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function collectionNavigationPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
116
|
-
let start = index;
|
|
117
|
-
let token = ResourcePath.collectionPath(value, index, metadataContext) ||
|
|
118
|
-
Expressions.refExpr(value, index);
|
|
119
|
-
if (token) return token;
|
|
120
|
-
|
|
121
|
-
let predicate = Expressions.keyPredicate(value, index, metadataContext);
|
|
122
|
-
if (predicate) {
|
|
123
|
-
let tokenValue: any = { predicate };
|
|
124
|
-
index = predicate.next;
|
|
125
|
-
|
|
126
|
-
let navigation = ResourcePath.singleNavigation(value, index, metadataContext);
|
|
127
|
-
if (navigation) {
|
|
128
|
-
tokenValue = { predicate, navigation };
|
|
129
|
-
index = navigation.next;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return Lexer.tokenize(value, start, index, tokenValue, Lexer.TokenType.CollectionNavigationPath, navigation || <any>{ metadata: metadataContext });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function singleNavigation(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
137
|
-
let token = ResourcePath.boundOperation(value, index, false, metadataContext) ||
|
|
138
|
-
Expressions.refExpr(value, index) ||
|
|
139
|
-
Expressions.valueExpr(value, index);
|
|
140
|
-
if (token) return token;
|
|
141
|
-
|
|
142
|
-
let start = index;
|
|
143
|
-
let name;
|
|
144
|
-
|
|
145
|
-
if (value[index] === 0x2f) {
|
|
146
|
-
name = NameOrIdentifier.qualifiedEntityTypeName(value, index + 1, metadataContext);
|
|
147
|
-
if (name) {
|
|
148
|
-
index = name.next;
|
|
149
|
-
metadataContext = name.value.metadata;
|
|
150
|
-
delete name.value.metadata;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (value[index] === 0x2f) {
|
|
155
|
-
token = ResourcePath.propertyPath(value, index + 1, metadataContext);
|
|
156
|
-
if (token) index = token.next;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!name && !token) return;
|
|
160
|
-
|
|
161
|
-
return Lexer.tokenize(value, start, index, { name: name, path: token }, Lexer.TokenType.SingleNavigation, token);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function propertyPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
165
|
-
let token =
|
|
166
|
-
NameOrIdentifier.entityColNavigationProperty(value, index, metadataContext) ||
|
|
167
|
-
NameOrIdentifier.entityNavigationProperty(value, index, metadataContext) ||
|
|
168
|
-
NameOrIdentifier.complexColProperty(value, index, metadataContext) ||
|
|
169
|
-
NameOrIdentifier.complexProperty(value, index, metadataContext) ||
|
|
170
|
-
NameOrIdentifier.primitiveColProperty(value, index, metadataContext) ||
|
|
171
|
-
NameOrIdentifier.primitiveProperty(value, index, metadataContext) ||
|
|
172
|
-
NameOrIdentifier.streamProperty(value, index, metadataContext);
|
|
173
|
-
|
|
174
|
-
if (!token) return;
|
|
175
|
-
let start = index;
|
|
176
|
-
index = token.next;
|
|
177
|
-
|
|
178
|
-
let navigation;
|
|
179
|
-
switch (token.type) {
|
|
180
|
-
case Lexer.TokenType.EntityCollectionNavigationProperty:
|
|
181
|
-
navigation = ResourcePath.collectionNavigation(value, index, token.metadata);
|
|
182
|
-
delete token.metadata;
|
|
183
|
-
break;
|
|
184
|
-
case Lexer.TokenType.EntityNavigationProperty:
|
|
185
|
-
navigation = ResourcePath.singleNavigation(value, index, token.metadata);
|
|
186
|
-
delete token.metadata;
|
|
187
|
-
break;
|
|
188
|
-
case Lexer.TokenType.ComplexCollectionProperty:
|
|
189
|
-
navigation = ResourcePath.collectionPath(value, index, token.metadata);
|
|
190
|
-
delete token.metadata;
|
|
191
|
-
break;
|
|
192
|
-
case Lexer.TokenType.ComplexProperty:
|
|
193
|
-
navigation = ResourcePath.complexPath(value, index, token.metadata);
|
|
194
|
-
delete token.metadata;
|
|
195
|
-
break;
|
|
196
|
-
case Lexer.TokenType.PrimitiveCollectionProperty:
|
|
197
|
-
navigation = ResourcePath.collectionPath(value, index, token.metadata);
|
|
198
|
-
delete token.metadata;
|
|
199
|
-
break;
|
|
200
|
-
case Lexer.TokenType.PrimitiveKeyProperty:
|
|
201
|
-
case Lexer.TokenType.PrimitiveProperty:
|
|
202
|
-
navigation = ResourcePath.singlePath(value, index, token.metadata);
|
|
203
|
-
delete token.metadata;
|
|
204
|
-
break;
|
|
205
|
-
case Lexer.TokenType.StreamProperty:
|
|
206
|
-
navigation = ResourcePath.boundOperation(value, index, token.metadata);
|
|
207
|
-
delete token.metadata;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (navigation) index = navigation.next;
|
|
212
|
-
|
|
213
|
-
return Lexer.tokenize(value, start, index, { path: token, navigation }, Lexer.TokenType.PropertyPath, navigation);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export function collectionPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
217
|
-
return Expressions.countExpr(value, index) ||
|
|
218
|
-
ResourcePath.boundOperation(value, index, true, metadataContext);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function singlePath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
222
|
-
return Expressions.valueExpr(value, index) ||
|
|
223
|
-
ResourcePath.boundOperation(value, index, false, metadataContext);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export function complexPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
227
|
-
let start = index;
|
|
228
|
-
let name, token;
|
|
229
|
-
if (value[index] === 0x2f) {
|
|
230
|
-
name = NameOrIdentifier.qualifiedComplexTypeName(value, index + 1, metadataContext);
|
|
231
|
-
if (name) index = name.next;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (value[index] === 0x2f) {
|
|
235
|
-
token = ResourcePath.propertyPath(value, index + 1, metadataContext);
|
|
236
|
-
if (!token) return;
|
|
237
|
-
index = token.next;
|
|
238
|
-
}else token = ResourcePath.boundOperation(value, index, false, metadataContext);
|
|
239
|
-
|
|
240
|
-
if (!name && !token) return;
|
|
241
|
-
|
|
242
|
-
return Lexer.tokenize(value, start, index, { name: name, path: token }, Lexer.TokenType.ComplexPath, token);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function boundOperation(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
246
|
-
if (value[index] !== 0x2f) return;
|
|
247
|
-
let start = index;
|
|
248
|
-
index++;
|
|
249
|
-
|
|
250
|
-
let operation = ResourcePath.boundEntityColFuncCall(value, index, isCollection, metadataContext) ||
|
|
251
|
-
ResourcePath.boundEntityFuncCall(value, index, isCollection, metadataContext) ||
|
|
252
|
-
ResourcePath.boundComplexColFuncCall(value, index, isCollection, metadataContext) ||
|
|
253
|
-
ResourcePath.boundComplexFuncCall(value, index, isCollection, metadataContext) ||
|
|
254
|
-
ResourcePath.boundPrimitiveColFuncCall(value, index, isCollection, metadataContext) ||
|
|
255
|
-
ResourcePath.boundPrimitiveFuncCall(value, index, isCollection, metadataContext) ||
|
|
256
|
-
ResourcePath.boundActionCall(value, index, isCollection, metadataContext);
|
|
257
|
-
if (!operation) return;
|
|
258
|
-
index = operation.next;
|
|
259
|
-
|
|
260
|
-
let name, navigation;
|
|
261
|
-
switch (operation.type) {
|
|
262
|
-
case Lexer.TokenType.BoundActionCall:
|
|
263
|
-
break;
|
|
264
|
-
case Lexer.TokenType.BoundEntityCollectionFunctionCall:
|
|
265
|
-
navigation = ResourcePath.collectionNavigation(value, index, operation.value.call.metadata);
|
|
266
|
-
delete operation.metadata;
|
|
267
|
-
break;
|
|
268
|
-
case Lexer.TokenType.BoundEntityFunctionCall:
|
|
269
|
-
navigation = ResourcePath.singleNavigation(value, index, operation.value.call.metadata);
|
|
270
|
-
delete operation.metadata;
|
|
271
|
-
break;
|
|
272
|
-
case Lexer.TokenType.BoundComplexCollectionFunctionCall:
|
|
273
|
-
if (value[index] === 0x2f) {
|
|
274
|
-
name = NameOrIdentifier.qualifiedComplexTypeName(value, index + 1, operation.value.call.metadata);
|
|
275
|
-
if (name) index = name.next;
|
|
276
|
-
}
|
|
277
|
-
navigation = ResourcePath.collectionPath(value, index, operation.value.call.metadata);
|
|
278
|
-
delete operation.metadata;
|
|
279
|
-
break;
|
|
280
|
-
case Lexer.TokenType.BoundComplexFunctionCall:
|
|
281
|
-
navigation = ResourcePath.complexPath(value, index, operation.value.call.metadata);
|
|
282
|
-
delete operation.metadata;
|
|
283
|
-
break;
|
|
284
|
-
case Lexer.TokenType.BoundPrimitiveCollectionFunctionCall:
|
|
285
|
-
navigation = ResourcePath.collectionPath(value, index, operation.value.call.metadata);
|
|
286
|
-
delete operation.metadata;
|
|
287
|
-
break;
|
|
288
|
-
case Lexer.TokenType.BoundPrimitiveFunctionCall:
|
|
289
|
-
navigation = ResourcePath.singlePath(value, index, operation.value.call.metadata);
|
|
290
|
-
delete operation.metadata;
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (navigation) index = navigation.next;
|
|
295
|
-
|
|
296
|
-
return Lexer.tokenize(value, start, index, { operation, name, navigation }, Lexer.TokenType.BoundOperation, navigation);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function boundActionCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
300
|
-
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
301
|
-
if (namespaceNext === index) return;
|
|
302
|
-
let start = index;
|
|
303
|
-
index = namespaceNext;
|
|
304
|
-
|
|
305
|
-
if (value[index] !== 0x2e) return;
|
|
306
|
-
index++;
|
|
307
|
-
|
|
308
|
-
let action = NameOrIdentifier.action(value, index, isCollection, metadataContext);
|
|
309
|
-
if (!action) return;
|
|
310
|
-
action.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
311
|
-
|
|
312
|
-
return Lexer.tokenize(value, start, action.next, action, Lexer.TokenType.BoundActionCall, action);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export function boundFunctionCall(value: Utils.SourceArray, index: number, odataFunction: Function, tokenType: Lexer.TokenType, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
316
|
-
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
317
|
-
if (namespaceNext === index) return;
|
|
318
|
-
let start = index;
|
|
319
|
-
index = namespaceNext;
|
|
320
|
-
|
|
321
|
-
if (value[index] !== 0x2e) return;
|
|
322
|
-
index++;
|
|
323
|
-
|
|
324
|
-
let call = odataFunction(value, index, isCollection, metadataContext);
|
|
325
|
-
if (!call) return;
|
|
326
|
-
call.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
327
|
-
index = call.next;
|
|
328
|
-
|
|
329
|
-
let params = ResourcePath.functionParameters(value, index);
|
|
330
|
-
if (!params) return;
|
|
331
|
-
index = params.next;
|
|
332
|
-
|
|
333
|
-
return Lexer.tokenize(value, start, index, { call, params }, tokenType, call);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export function boundEntityFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
337
|
-
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.entityFunction, Lexer.TokenType.BoundEntityFunctionCall, isCollection, metadataContext);
|
|
338
|
-
}
|
|
339
|
-
export function boundEntityColFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
340
|
-
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.entityColFunction, Lexer.TokenType.BoundEntityCollectionFunctionCall, isCollection, metadataContext);
|
|
341
|
-
}
|
|
342
|
-
export function boundComplexFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
343
|
-
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.complexFunction, Lexer.TokenType.BoundComplexFunctionCall, isCollection, metadataContext);
|
|
344
|
-
}
|
|
345
|
-
export function boundComplexColFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
346
|
-
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.complexColFunction, Lexer.TokenType.BoundComplexCollectionFunctionCall, isCollection, metadataContext);
|
|
347
|
-
}
|
|
348
|
-
export function boundPrimitiveFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
349
|
-
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.primitiveFunction, Lexer.TokenType.BoundPrimitiveFunctionCall, isCollection, metadataContext);
|
|
350
|
-
}
|
|
351
|
-
export function boundPrimitiveColFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
352
|
-
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.primitiveColFunction, Lexer.TokenType.BoundPrimitiveCollectionFunctionCall, isCollection, metadataContext);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export function actionImportCall(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
356
|
-
let action = NameOrIdentifier.actionImport(value, index, metadataContext);
|
|
357
|
-
if (action) return Lexer.tokenize(value, index, action.next, action, Lexer.TokenType.ActionImportCall, action);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
export function functionImportCall(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
361
|
-
let fnImport = NameOrIdentifier.entityFunctionImport(value, index, metadataContext) ||
|
|
362
|
-
NameOrIdentifier.entityColFunctionImport(value, index, metadataContext) ||
|
|
363
|
-
NameOrIdentifier.complexFunctionImport(value, index, metadataContext) ||
|
|
364
|
-
NameOrIdentifier.complexColFunctionImport(value, index, metadataContext) ||
|
|
365
|
-
NameOrIdentifier.primitiveFunctionImport(value, index, metadataContext) ||
|
|
366
|
-
NameOrIdentifier.primitiveColFunctionImport(value, index, metadataContext);
|
|
367
|
-
|
|
368
|
-
if (!fnImport) return;
|
|
369
|
-
let start = index;
|
|
370
|
-
index = fnImport.next;
|
|
371
|
-
|
|
372
|
-
let params = ResourcePath.functionParameters(value, index);
|
|
373
|
-
if (!params) return;
|
|
374
|
-
index = params.next;
|
|
375
|
-
|
|
376
|
-
return Lexer.tokenize(value, start, index, { import: fnImport, params: params.value }, <Lexer.TokenType>(fnImport.type + "Call"), fnImport);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export function functionParameters(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
380
|
-
let open = Lexer.OPEN(value, index);
|
|
381
|
-
if (!open) return;
|
|
382
|
-
let start = index;
|
|
383
|
-
index = open;
|
|
384
|
-
|
|
385
|
-
let params = [];
|
|
386
|
-
let token = ResourcePath.functionParameter(value, index);
|
|
387
|
-
while (token) {
|
|
388
|
-
params.push(token);
|
|
389
|
-
index = token.next;
|
|
390
|
-
|
|
391
|
-
let comma = Lexer.COMMA(value, index);
|
|
392
|
-
if (comma) {
|
|
393
|
-
index = comma;
|
|
394
|
-
token = ResourcePath.functionParameter(value, index);
|
|
395
|
-
if (!token) return;
|
|
396
|
-
}else break;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
let close = Lexer.CLOSE(value, index);
|
|
400
|
-
if (!close) return;
|
|
401
|
-
index = close;
|
|
402
|
-
|
|
403
|
-
return Lexer.tokenize(value, start, index, params, Lexer.TokenType.FunctionParameters);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
export function functionParameter(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
407
|
-
let name = Expressions.parameterName(value, index);
|
|
408
|
-
if (!name) return;
|
|
409
|
-
let start = index;
|
|
410
|
-
index = name.next;
|
|
411
|
-
|
|
412
|
-
let eq = Lexer.EQ(value, index);
|
|
413
|
-
if (!eq) return;
|
|
414
|
-
index = eq;
|
|
415
|
-
|
|
416
|
-
let token = Expressions.parameterAlias(value, index) ||
|
|
417
|
-
PrimitiveLiteral.primitiveLiteral(value, index);
|
|
418
|
-
|
|
419
|
-
if (!token) return;
|
|
420
|
-
index = token.next;
|
|
421
|
-
|
|
422
|
-
return Lexer.tokenize(value, start, index, { name, value: token }, Lexer.TokenType.FunctionParameter);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export function crossjoin(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
426
|
-
if (!Utils.equals(value, index, "$crossjoin")) return;
|
|
427
|
-
let start = index;
|
|
428
|
-
index += 10;
|
|
429
|
-
|
|
430
|
-
let open = Lexer.OPEN(value, index);
|
|
431
|
-
if (!open) return;
|
|
432
|
-
index = open;
|
|
433
|
-
|
|
434
|
-
let names = [];
|
|
435
|
-
let token = NameOrIdentifier.entitySetName(value, index, metadataContext);
|
|
436
|
-
if (!token) return;
|
|
437
|
-
|
|
438
|
-
while (token) {
|
|
439
|
-
names.push(token);
|
|
440
|
-
index = token.next;
|
|
441
|
-
|
|
442
|
-
let comma = Lexer.COMMA(value, index);
|
|
443
|
-
if (comma) {
|
|
444
|
-
index = comma;
|
|
445
|
-
token = NameOrIdentifier.entitySetName(value, index, metadataContext);
|
|
446
|
-
if (!token) return;
|
|
447
|
-
}else break;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
let close = Lexer.CLOSE(value, index);
|
|
451
|
-
if (!close) return;
|
|
452
|
-
|
|
453
|
-
return Lexer.tokenize(value, start, index, { names }, Lexer.TokenType.Crossjoin);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export function all(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
457
|
-
if (Utils.equals(value, index, "$all")) return Lexer.tokenize(value, index, index + 4, "$all", Lexer.TokenType.AllResource);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
export default ResourcePath;
|
|
1
|
+
import Utils from "./utils";
|
|
2
|
+
import Lexer from "./lexer";
|
|
3
|
+
import PrimitiveLiteral from "./primitiveLiteral";
|
|
4
|
+
import NameOrIdentifier from "./nameOrIdentifier";
|
|
5
|
+
import Expressions from "./expressions";
|
|
6
|
+
|
|
7
|
+
export namespace ResourcePath {
|
|
8
|
+
export function resourcePath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
9
|
+
if (value[index] === 0x2f) index++;
|
|
10
|
+
let token = ResourcePath.batch(value, index) ||
|
|
11
|
+
ResourcePath.entity(value, index, metadataContext) ||
|
|
12
|
+
ResourcePath.metadata(value, index);
|
|
13
|
+
if (token) return token;
|
|
14
|
+
|
|
15
|
+
let resource = NameOrIdentifier.entitySetName(value, index, metadataContext) ||
|
|
16
|
+
ResourcePath.functionImportCall(value, index, metadataContext) ||
|
|
17
|
+
ResourcePath.crossjoin(value, index) ||
|
|
18
|
+
ResourcePath.all(value, index) ||
|
|
19
|
+
ResourcePath.actionImportCall(value, index, metadataContext) ||
|
|
20
|
+
NameOrIdentifier.singletonEntity(value, index);
|
|
21
|
+
|
|
22
|
+
if (!resource) return;
|
|
23
|
+
let start = index;
|
|
24
|
+
index = resource.next;
|
|
25
|
+
let navigation: Lexer.Token;
|
|
26
|
+
|
|
27
|
+
switch (resource.type) {
|
|
28
|
+
case Lexer.TokenType.EntitySetName:
|
|
29
|
+
navigation = ResourcePath.collectionNavigation(value, resource.next, resource.metadata);
|
|
30
|
+
metadataContext = resource.metadata;
|
|
31
|
+
delete resource.metadata;
|
|
32
|
+
break;
|
|
33
|
+
case Lexer.TokenType.EntityCollectionFunctionImportCall:
|
|
34
|
+
navigation = ResourcePath.collectionNavigation(value, resource.next, resource.value.import.metadata);
|
|
35
|
+
metadataContext = resource.value.import.metadata;
|
|
36
|
+
delete resource.value.import.metadata;
|
|
37
|
+
break;
|
|
38
|
+
case Lexer.TokenType.SingletonEntity:
|
|
39
|
+
navigation = ResourcePath.singleNavigation(value, resource.next, resource.metadata);
|
|
40
|
+
metadataContext = resource.metadata;
|
|
41
|
+
delete resource.metadata;
|
|
42
|
+
break;
|
|
43
|
+
case Lexer.TokenType.EntityFunctionImportCall:
|
|
44
|
+
navigation = ResourcePath.singleNavigation(value, resource.next, resource.value.import.metadata);
|
|
45
|
+
metadataContext = resource.value.import.metadata;
|
|
46
|
+
delete resource.value.import.metadata;
|
|
47
|
+
break;
|
|
48
|
+
case Lexer.TokenType.ComplexCollectionFunctionImportCall:
|
|
49
|
+
case Lexer.TokenType.PrimitiveCollectionFunctionImportCall:
|
|
50
|
+
navigation = ResourcePath.collectionPath(value, resource.next, resource.value.import.metadata);
|
|
51
|
+
metadataContext = resource.value.import.metadata;
|
|
52
|
+
delete resource.value.import.metadata;
|
|
53
|
+
break;
|
|
54
|
+
case Lexer.TokenType.ComplexFunctionImportCall:
|
|
55
|
+
navigation = ResourcePath.complexPath(value, resource.next, resource.value.import.metadata);
|
|
56
|
+
metadataContext = resource.value.import.metadata;
|
|
57
|
+
delete resource.value.import.metadata;
|
|
58
|
+
break;
|
|
59
|
+
case Lexer.TokenType.PrimitiveFunctionImportCall:
|
|
60
|
+
navigation = ResourcePath.singlePath(value, resource.next, resource.value.import.metadata);
|
|
61
|
+
metadataContext = resource.value.import.metadata;
|
|
62
|
+
delete resource.value.import.metadata;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (navigation) index = navigation.next;
|
|
67
|
+
if (value[index] === 0x2f) index++;
|
|
68
|
+
if (resource) return Lexer.tokenize(value, start, index, { resource, navigation }, Lexer.TokenType.ResourcePath, navigation || <any>{ metadata: metadataContext });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function batch(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
72
|
+
if (Utils.equals(value, index, "$batch")) return Lexer.tokenize(value, index, index + 6, "$batch", Lexer.TokenType.Batch);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function entity(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
76
|
+
if (Utils.equals(value, index, "$entity")) {
|
|
77
|
+
let start = index;
|
|
78
|
+
index += 7;
|
|
79
|
+
|
|
80
|
+
let name;
|
|
81
|
+
if (value[index] === 0x2f) {
|
|
82
|
+
name = NameOrIdentifier.qualifiedEntityTypeName(value, index + 1, metadataContext);
|
|
83
|
+
if (!name) return;
|
|
84
|
+
index = name.next;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return Lexer.tokenize(value, start, index, name || "$entity", Lexer.TokenType.Entity);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function metadata(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
92
|
+
if (Utils.equals(value, index, "$metadata")) return Lexer.tokenize(value, index, index + 9, "$metadata", Lexer.TokenType.Metadata);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function collectionNavigation(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
96
|
+
let start = index;
|
|
97
|
+
let name;
|
|
98
|
+
if (value[index] === 0x2f) {
|
|
99
|
+
name = NameOrIdentifier.qualifiedEntityTypeName(value, index + 1, metadataContext);
|
|
100
|
+
if (name) {
|
|
101
|
+
index = name.next;
|
|
102
|
+
metadataContext = name.value.metadata;
|
|
103
|
+
delete name.value.metadata;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let path = ResourcePath.collectionNavigationPath(value, index, metadataContext);
|
|
108
|
+
if (path) index = path.next;
|
|
109
|
+
|
|
110
|
+
if (!name && !path) return;
|
|
111
|
+
|
|
112
|
+
return Lexer.tokenize(value, start, index, { name, path }, Lexer.TokenType.CollectionNavigation, path || name);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function collectionNavigationPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
116
|
+
let start = index;
|
|
117
|
+
let token = ResourcePath.collectionPath(value, index, metadataContext) ||
|
|
118
|
+
Expressions.refExpr(value, index);
|
|
119
|
+
if (token) return token;
|
|
120
|
+
|
|
121
|
+
let predicate = Expressions.keyPredicate(value, index, metadataContext);
|
|
122
|
+
if (predicate) {
|
|
123
|
+
let tokenValue: any = { predicate };
|
|
124
|
+
index = predicate.next;
|
|
125
|
+
|
|
126
|
+
let navigation = ResourcePath.singleNavigation(value, index, metadataContext);
|
|
127
|
+
if (navigation) {
|
|
128
|
+
tokenValue = { predicate, navigation };
|
|
129
|
+
index = navigation.next;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return Lexer.tokenize(value, start, index, tokenValue, Lexer.TokenType.CollectionNavigationPath, navigation || <any>{ metadata: metadataContext });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function singleNavigation(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
137
|
+
let token = ResourcePath.boundOperation(value, index, false, metadataContext) ||
|
|
138
|
+
Expressions.refExpr(value, index) ||
|
|
139
|
+
Expressions.valueExpr(value, index);
|
|
140
|
+
if (token) return token;
|
|
141
|
+
|
|
142
|
+
let start = index;
|
|
143
|
+
let name;
|
|
144
|
+
|
|
145
|
+
if (value[index] === 0x2f) {
|
|
146
|
+
name = NameOrIdentifier.qualifiedEntityTypeName(value, index + 1, metadataContext);
|
|
147
|
+
if (name) {
|
|
148
|
+
index = name.next;
|
|
149
|
+
metadataContext = name.value.metadata;
|
|
150
|
+
delete name.value.metadata;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (value[index] === 0x2f) {
|
|
155
|
+
token = ResourcePath.propertyPath(value, index + 1, metadataContext);
|
|
156
|
+
if (token) index = token.next;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!name && !token) return;
|
|
160
|
+
|
|
161
|
+
return Lexer.tokenize(value, start, index, { name: name, path: token }, Lexer.TokenType.SingleNavigation, token);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function propertyPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
165
|
+
let token =
|
|
166
|
+
NameOrIdentifier.entityColNavigationProperty(value, index, metadataContext) ||
|
|
167
|
+
NameOrIdentifier.entityNavigationProperty(value, index, metadataContext) ||
|
|
168
|
+
NameOrIdentifier.complexColProperty(value, index, metadataContext) ||
|
|
169
|
+
NameOrIdentifier.complexProperty(value, index, metadataContext) ||
|
|
170
|
+
NameOrIdentifier.primitiveColProperty(value, index, metadataContext) ||
|
|
171
|
+
NameOrIdentifier.primitiveProperty(value, index, metadataContext) ||
|
|
172
|
+
NameOrIdentifier.streamProperty(value, index, metadataContext);
|
|
173
|
+
|
|
174
|
+
if (!token) return;
|
|
175
|
+
let start = index;
|
|
176
|
+
index = token.next;
|
|
177
|
+
|
|
178
|
+
let navigation;
|
|
179
|
+
switch (token.type) {
|
|
180
|
+
case Lexer.TokenType.EntityCollectionNavigationProperty:
|
|
181
|
+
navigation = ResourcePath.collectionNavigation(value, index, token.metadata);
|
|
182
|
+
delete token.metadata;
|
|
183
|
+
break;
|
|
184
|
+
case Lexer.TokenType.EntityNavigationProperty:
|
|
185
|
+
navigation = ResourcePath.singleNavigation(value, index, token.metadata);
|
|
186
|
+
delete token.metadata;
|
|
187
|
+
break;
|
|
188
|
+
case Lexer.TokenType.ComplexCollectionProperty:
|
|
189
|
+
navigation = ResourcePath.collectionPath(value, index, token.metadata);
|
|
190
|
+
delete token.metadata;
|
|
191
|
+
break;
|
|
192
|
+
case Lexer.TokenType.ComplexProperty:
|
|
193
|
+
navigation = ResourcePath.complexPath(value, index, token.metadata);
|
|
194
|
+
delete token.metadata;
|
|
195
|
+
break;
|
|
196
|
+
case Lexer.TokenType.PrimitiveCollectionProperty:
|
|
197
|
+
navigation = ResourcePath.collectionPath(value, index, token.metadata);
|
|
198
|
+
delete token.metadata;
|
|
199
|
+
break;
|
|
200
|
+
case Lexer.TokenType.PrimitiveKeyProperty:
|
|
201
|
+
case Lexer.TokenType.PrimitiveProperty:
|
|
202
|
+
navigation = ResourcePath.singlePath(value, index, token.metadata);
|
|
203
|
+
delete token.metadata;
|
|
204
|
+
break;
|
|
205
|
+
case Lexer.TokenType.StreamProperty:
|
|
206
|
+
navigation = ResourcePath.boundOperation(value, index, token.metadata);
|
|
207
|
+
delete token.metadata;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (navigation) index = navigation.next;
|
|
212
|
+
|
|
213
|
+
return Lexer.tokenize(value, start, index, { path: token, navigation }, Lexer.TokenType.PropertyPath, navigation);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function collectionPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
217
|
+
return Expressions.countExpr(value, index) ||
|
|
218
|
+
ResourcePath.boundOperation(value, index, true, metadataContext);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function singlePath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
222
|
+
return Expressions.valueExpr(value, index) ||
|
|
223
|
+
ResourcePath.boundOperation(value, index, false, metadataContext);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function complexPath(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
227
|
+
let start = index;
|
|
228
|
+
let name, token;
|
|
229
|
+
if (value[index] === 0x2f) {
|
|
230
|
+
name = NameOrIdentifier.qualifiedComplexTypeName(value, index + 1, metadataContext);
|
|
231
|
+
if (name) index = name.next;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (value[index] === 0x2f) {
|
|
235
|
+
token = ResourcePath.propertyPath(value, index + 1, metadataContext);
|
|
236
|
+
if (!token) return;
|
|
237
|
+
index = token.next;
|
|
238
|
+
}else token = ResourcePath.boundOperation(value, index, false, metadataContext);
|
|
239
|
+
|
|
240
|
+
if (!name && !token) return;
|
|
241
|
+
|
|
242
|
+
return Lexer.tokenize(value, start, index, { name: name, path: token }, Lexer.TokenType.ComplexPath, token);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function boundOperation(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
246
|
+
if (value[index] !== 0x2f) return;
|
|
247
|
+
let start = index;
|
|
248
|
+
index++;
|
|
249
|
+
|
|
250
|
+
let operation = ResourcePath.boundEntityColFuncCall(value, index, isCollection, metadataContext) ||
|
|
251
|
+
ResourcePath.boundEntityFuncCall(value, index, isCollection, metadataContext) ||
|
|
252
|
+
ResourcePath.boundComplexColFuncCall(value, index, isCollection, metadataContext) ||
|
|
253
|
+
ResourcePath.boundComplexFuncCall(value, index, isCollection, metadataContext) ||
|
|
254
|
+
ResourcePath.boundPrimitiveColFuncCall(value, index, isCollection, metadataContext) ||
|
|
255
|
+
ResourcePath.boundPrimitiveFuncCall(value, index, isCollection, metadataContext) ||
|
|
256
|
+
ResourcePath.boundActionCall(value, index, isCollection, metadataContext);
|
|
257
|
+
if (!operation) return;
|
|
258
|
+
index = operation.next;
|
|
259
|
+
|
|
260
|
+
let name, navigation;
|
|
261
|
+
switch (operation.type) {
|
|
262
|
+
case Lexer.TokenType.BoundActionCall:
|
|
263
|
+
break;
|
|
264
|
+
case Lexer.TokenType.BoundEntityCollectionFunctionCall:
|
|
265
|
+
navigation = ResourcePath.collectionNavigation(value, index, operation.value.call.metadata);
|
|
266
|
+
delete operation.metadata;
|
|
267
|
+
break;
|
|
268
|
+
case Lexer.TokenType.BoundEntityFunctionCall:
|
|
269
|
+
navigation = ResourcePath.singleNavigation(value, index, operation.value.call.metadata);
|
|
270
|
+
delete operation.metadata;
|
|
271
|
+
break;
|
|
272
|
+
case Lexer.TokenType.BoundComplexCollectionFunctionCall:
|
|
273
|
+
if (value[index] === 0x2f) {
|
|
274
|
+
name = NameOrIdentifier.qualifiedComplexTypeName(value, index + 1, operation.value.call.metadata);
|
|
275
|
+
if (name) index = name.next;
|
|
276
|
+
}
|
|
277
|
+
navigation = ResourcePath.collectionPath(value, index, operation.value.call.metadata);
|
|
278
|
+
delete operation.metadata;
|
|
279
|
+
break;
|
|
280
|
+
case Lexer.TokenType.BoundComplexFunctionCall:
|
|
281
|
+
navigation = ResourcePath.complexPath(value, index, operation.value.call.metadata);
|
|
282
|
+
delete operation.metadata;
|
|
283
|
+
break;
|
|
284
|
+
case Lexer.TokenType.BoundPrimitiveCollectionFunctionCall:
|
|
285
|
+
navigation = ResourcePath.collectionPath(value, index, operation.value.call.metadata);
|
|
286
|
+
delete operation.metadata;
|
|
287
|
+
break;
|
|
288
|
+
case Lexer.TokenType.BoundPrimitiveFunctionCall:
|
|
289
|
+
navigation = ResourcePath.singlePath(value, index, operation.value.call.metadata);
|
|
290
|
+
delete operation.metadata;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (navigation) index = navigation.next;
|
|
295
|
+
|
|
296
|
+
return Lexer.tokenize(value, start, index, { operation, name, navigation }, Lexer.TokenType.BoundOperation, navigation);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function boundActionCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
300
|
+
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
301
|
+
if (namespaceNext === index) return;
|
|
302
|
+
let start = index;
|
|
303
|
+
index = namespaceNext;
|
|
304
|
+
|
|
305
|
+
if (value[index] !== 0x2e) return;
|
|
306
|
+
index++;
|
|
307
|
+
|
|
308
|
+
let action = NameOrIdentifier.action(value, index, isCollection, metadataContext);
|
|
309
|
+
if (!action) return;
|
|
310
|
+
action.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
311
|
+
|
|
312
|
+
return Lexer.tokenize(value, start, action.next, action, Lexer.TokenType.BoundActionCall, action);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function boundFunctionCall(value: Utils.SourceArray, index: number, odataFunction: Function, tokenType: Lexer.TokenType, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
316
|
+
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
317
|
+
if (namespaceNext === index) return;
|
|
318
|
+
let start = index;
|
|
319
|
+
index = namespaceNext;
|
|
320
|
+
|
|
321
|
+
if (value[index] !== 0x2e) return;
|
|
322
|
+
index++;
|
|
323
|
+
|
|
324
|
+
let call = odataFunction(value, index, isCollection, metadataContext);
|
|
325
|
+
if (!call) return;
|
|
326
|
+
call.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
327
|
+
index = call.next;
|
|
328
|
+
|
|
329
|
+
let params = ResourcePath.functionParameters(value, index);
|
|
330
|
+
if (!params) return;
|
|
331
|
+
index = params.next;
|
|
332
|
+
|
|
333
|
+
return Lexer.tokenize(value, start, index, { call, params }, tokenType, call);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function boundEntityFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
337
|
+
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.entityFunction, Lexer.TokenType.BoundEntityFunctionCall, isCollection, metadataContext);
|
|
338
|
+
}
|
|
339
|
+
export function boundEntityColFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
340
|
+
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.entityColFunction, Lexer.TokenType.BoundEntityCollectionFunctionCall, isCollection, metadataContext);
|
|
341
|
+
}
|
|
342
|
+
export function boundComplexFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
343
|
+
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.complexFunction, Lexer.TokenType.BoundComplexFunctionCall, isCollection, metadataContext);
|
|
344
|
+
}
|
|
345
|
+
export function boundComplexColFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
346
|
+
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.complexColFunction, Lexer.TokenType.BoundComplexCollectionFunctionCall, isCollection, metadataContext);
|
|
347
|
+
}
|
|
348
|
+
export function boundPrimitiveFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
349
|
+
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.primitiveFunction, Lexer.TokenType.BoundPrimitiveFunctionCall, isCollection, metadataContext);
|
|
350
|
+
}
|
|
351
|
+
export function boundPrimitiveColFuncCall(value: Utils.SourceArray, index: number, isCollection: boolean, metadataContext?: any): Lexer.Token {
|
|
352
|
+
return ResourcePath.boundFunctionCall(value, index, NameOrIdentifier.primitiveColFunction, Lexer.TokenType.BoundPrimitiveCollectionFunctionCall, isCollection, metadataContext);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function actionImportCall(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
356
|
+
let action = NameOrIdentifier.actionImport(value, index, metadataContext);
|
|
357
|
+
if (action) return Lexer.tokenize(value, index, action.next, action, Lexer.TokenType.ActionImportCall, action);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function functionImportCall(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
361
|
+
let fnImport = NameOrIdentifier.entityFunctionImport(value, index, metadataContext) ||
|
|
362
|
+
NameOrIdentifier.entityColFunctionImport(value, index, metadataContext) ||
|
|
363
|
+
NameOrIdentifier.complexFunctionImport(value, index, metadataContext) ||
|
|
364
|
+
NameOrIdentifier.complexColFunctionImport(value, index, metadataContext) ||
|
|
365
|
+
NameOrIdentifier.primitiveFunctionImport(value, index, metadataContext) ||
|
|
366
|
+
NameOrIdentifier.primitiveColFunctionImport(value, index, metadataContext);
|
|
367
|
+
|
|
368
|
+
if (!fnImport) return;
|
|
369
|
+
let start = index;
|
|
370
|
+
index = fnImport.next;
|
|
371
|
+
|
|
372
|
+
let params = ResourcePath.functionParameters(value, index);
|
|
373
|
+
if (!params) return;
|
|
374
|
+
index = params.next;
|
|
375
|
+
|
|
376
|
+
return Lexer.tokenize(value, start, index, { import: fnImport, params: params.value }, <Lexer.TokenType>(fnImport.type + "Call"), fnImport);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function functionParameters(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
380
|
+
let open = Lexer.OPEN(value, index);
|
|
381
|
+
if (!open) return;
|
|
382
|
+
let start = index;
|
|
383
|
+
index = open;
|
|
384
|
+
|
|
385
|
+
let params = [];
|
|
386
|
+
let token = ResourcePath.functionParameter(value, index);
|
|
387
|
+
while (token) {
|
|
388
|
+
params.push(token);
|
|
389
|
+
index = token.next;
|
|
390
|
+
|
|
391
|
+
let comma = Lexer.COMMA(value, index);
|
|
392
|
+
if (comma) {
|
|
393
|
+
index = comma;
|
|
394
|
+
token = ResourcePath.functionParameter(value, index);
|
|
395
|
+
if (!token) return;
|
|
396
|
+
}else break;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
let close = Lexer.CLOSE(value, index);
|
|
400
|
+
if (!close) return;
|
|
401
|
+
index = close;
|
|
402
|
+
|
|
403
|
+
return Lexer.tokenize(value, start, index, params, Lexer.TokenType.FunctionParameters);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function functionParameter(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
407
|
+
let name = Expressions.parameterName(value, index);
|
|
408
|
+
if (!name) return;
|
|
409
|
+
let start = index;
|
|
410
|
+
index = name.next;
|
|
411
|
+
|
|
412
|
+
let eq = Lexer.EQ(value, index);
|
|
413
|
+
if (!eq) return;
|
|
414
|
+
index = eq;
|
|
415
|
+
|
|
416
|
+
let token = Expressions.parameterAlias(value, index) ||
|
|
417
|
+
PrimitiveLiteral.primitiveLiteral(value, index);
|
|
418
|
+
|
|
419
|
+
if (!token) return;
|
|
420
|
+
index = token.next;
|
|
421
|
+
|
|
422
|
+
return Lexer.tokenize(value, start, index, { name, value: token }, Lexer.TokenType.FunctionParameter);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export function crossjoin(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
426
|
+
if (!Utils.equals(value, index, "$crossjoin")) return;
|
|
427
|
+
let start = index;
|
|
428
|
+
index += 10;
|
|
429
|
+
|
|
430
|
+
let open = Lexer.OPEN(value, index);
|
|
431
|
+
if (!open) return;
|
|
432
|
+
index = open;
|
|
433
|
+
|
|
434
|
+
let names = [];
|
|
435
|
+
let token = NameOrIdentifier.entitySetName(value, index, metadataContext);
|
|
436
|
+
if (!token) return;
|
|
437
|
+
|
|
438
|
+
while (token) {
|
|
439
|
+
names.push(token);
|
|
440
|
+
index = token.next;
|
|
441
|
+
|
|
442
|
+
let comma = Lexer.COMMA(value, index);
|
|
443
|
+
if (comma) {
|
|
444
|
+
index = comma;
|
|
445
|
+
token = NameOrIdentifier.entitySetName(value, index, metadataContext);
|
|
446
|
+
if (!token) return;
|
|
447
|
+
}else break;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
let close = Lexer.CLOSE(value, index);
|
|
451
|
+
if (!close) return;
|
|
452
|
+
|
|
453
|
+
return Lexer.tokenize(value, start, index, { names }, Lexer.TokenType.Crossjoin);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export function all(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
457
|
+
if (Utils.equals(value, index, "$all")) return Lexer.tokenize(value, index, index + 4, "$all", Lexer.TokenType.AllResource);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export default ResourcePath;
|