@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/nameOrIdentifier.ts
CHANGED
|
@@ -1,749 +1,749 @@
|
|
|
1
|
-
import Utils from "./utils";
|
|
2
|
-
import Lexer from "./lexer";
|
|
3
|
-
import PrimitiveLiteral from "./primitiveLiteral";
|
|
4
|
-
|
|
5
|
-
export namespace NameOrIdentifier {
|
|
6
|
-
export function enumeration(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
7
|
-
let type = qualifiedEnumTypeName(value, index);
|
|
8
|
-
if (!type) return;
|
|
9
|
-
let start = index;
|
|
10
|
-
index = type.next;
|
|
11
|
-
|
|
12
|
-
let squote = Lexer.SQUOTE(value, index);
|
|
13
|
-
if (!squote) return;
|
|
14
|
-
index = squote;
|
|
15
|
-
|
|
16
|
-
let enumVal = NameOrIdentifier.enumValue(value, index);
|
|
17
|
-
if (!enumVal) return;
|
|
18
|
-
index = enumVal.next;
|
|
19
|
-
|
|
20
|
-
squote = Lexer.SQUOTE(value, index);
|
|
21
|
-
if (!squote) return;
|
|
22
|
-
index = squote;
|
|
23
|
-
|
|
24
|
-
return Lexer.tokenize(value, start, index, {
|
|
25
|
-
name: type,
|
|
26
|
-
value: enumVal
|
|
27
|
-
}, Lexer.TokenType.Enum);
|
|
28
|
-
}
|
|
29
|
-
export function enumValue(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
30
|
-
let val = NameOrIdentifier.singleEnumValue(value, index);
|
|
31
|
-
if (!val) return;
|
|
32
|
-
let start = index;
|
|
33
|
-
|
|
34
|
-
let arr = [];
|
|
35
|
-
while (val) {
|
|
36
|
-
arr.push(val);
|
|
37
|
-
index = val.next;
|
|
38
|
-
let comma = Lexer.COMMA(value, val.next);
|
|
39
|
-
if (comma) {
|
|
40
|
-
index = comma;
|
|
41
|
-
val = NameOrIdentifier.singleEnumValue(value, index);
|
|
42
|
-
}else break;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return Lexer.tokenize(value, start, index, { values: arr }, Lexer.TokenType.EnumValue);
|
|
46
|
-
}
|
|
47
|
-
export function singleEnumValue(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
48
|
-
return NameOrIdentifier.enumerationMember(value, index) ||
|
|
49
|
-
NameOrIdentifier.enumMemberValue(value, index);
|
|
50
|
-
}
|
|
51
|
-
export function enumMemberValue(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
52
|
-
let token = PrimitiveLiteral.int64Value(value, index);
|
|
53
|
-
if (token) {
|
|
54
|
-
token.type = Lexer.TokenType.EnumMemberValue;
|
|
55
|
-
return token;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export function singleQualifiedTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
59
|
-
return NameOrIdentifier.qualifiedEntityTypeName(value, index) ||
|
|
60
|
-
NameOrIdentifier.qualifiedComplexTypeName(value, index) ||
|
|
61
|
-
NameOrIdentifier.qualifiedTypeDefinitionName(value, index) ||
|
|
62
|
-
NameOrIdentifier.qualifiedEnumTypeName(value, index) ||
|
|
63
|
-
NameOrIdentifier.primitiveTypeName(value, index);
|
|
64
|
-
}
|
|
65
|
-
export function qualifiedTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
66
|
-
if (Utils.equals(value, index, "Collection")) {
|
|
67
|
-
let start = index;
|
|
68
|
-
index += 10;
|
|
69
|
-
|
|
70
|
-
let squote = Lexer.SQUOTE(value, index);
|
|
71
|
-
if (!squote) return;
|
|
72
|
-
index = squote;
|
|
73
|
-
|
|
74
|
-
let token = NameOrIdentifier.singleQualifiedTypeName(value, index);
|
|
75
|
-
if (!token) return;
|
|
76
|
-
else index = token.next;
|
|
77
|
-
|
|
78
|
-
squote = Lexer.SQUOTE(value, index);
|
|
79
|
-
if (!squote) return;
|
|
80
|
-
index = squote;
|
|
81
|
-
|
|
82
|
-
token.position = start;
|
|
83
|
-
token.next = index;
|
|
84
|
-
token.raw = Utils.stringify(value, token.position, token.next);
|
|
85
|
-
token.type = Lexer.TokenType.Collection;
|
|
86
|
-
} else return NameOrIdentifier.singleQualifiedTypeName(value, index);
|
|
87
|
-
}
|
|
88
|
-
export function qualifiedEntityTypeName(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
89
|
-
let start = index;
|
|
90
|
-
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
91
|
-
|
|
92
|
-
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
93
|
-
let schema;
|
|
94
|
-
if (typeof metadataContext === "object") {
|
|
95
|
-
schema = NameOrIdentifier.getMetadataRoot(metadataContext).schemas.filter(it => it.namespace === Utils.stringify(value, start, namespaceNext))[0];
|
|
96
|
-
}
|
|
97
|
-
let name = NameOrIdentifier.entityTypeName(value, namespaceNext + 1, schema);
|
|
98
|
-
if (!name) return;
|
|
99
|
-
name.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
100
|
-
|
|
101
|
-
return Lexer.tokenize(value, start, name.next, name, Lexer.TokenType.QualifiedEntityTypeName);
|
|
102
|
-
}
|
|
103
|
-
export function qualifiedComplexTypeName(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
104
|
-
let start = index;
|
|
105
|
-
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
106
|
-
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
107
|
-
let schema;
|
|
108
|
-
if (typeof metadataContext === "object") {
|
|
109
|
-
schema = NameOrIdentifier.getMetadataRoot(metadataContext).schemas.filter(it => it.namespace === Utils.stringify(value, start, namespaceNext))[0];
|
|
110
|
-
}
|
|
111
|
-
let name = NameOrIdentifier.complexTypeName(value, namespaceNext + 1, schema);
|
|
112
|
-
if (!name) return;
|
|
113
|
-
name.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
114
|
-
|
|
115
|
-
return Lexer.tokenize(value, start, name.next, name, Lexer.TokenType.QualifiedComplexTypeName);
|
|
116
|
-
}
|
|
117
|
-
export function qualifiedTypeDefinitionName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
118
|
-
let start = index;
|
|
119
|
-
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
120
|
-
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
121
|
-
let nameNext = NameOrIdentifier.typeDefinitionName(value, namespaceNext + 1);
|
|
122
|
-
if (nameNext && nameNext.next === namespaceNext + 1) return;
|
|
123
|
-
|
|
124
|
-
return Lexer.tokenize(value, start, nameNext.next, "TypeDefinitionName", Lexer.TokenType.Identifier);
|
|
125
|
-
}
|
|
126
|
-
export function qualifiedEnumTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
127
|
-
let start = index;
|
|
128
|
-
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
129
|
-
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
130
|
-
let nameNext = NameOrIdentifier.enumerationTypeName(value, namespaceNext + 1);
|
|
131
|
-
if (nameNext && nameNext.next === namespaceNext + 1) return;
|
|
132
|
-
|
|
133
|
-
return Lexer.tokenize(value, start, nameNext.next, "EnumTypeName", Lexer.TokenType.Identifier);
|
|
134
|
-
}
|
|
135
|
-
export function namespace(value: Utils.SourceArray, index: number): number {
|
|
136
|
-
let part = NameOrIdentifier.namespacePart(value, index);
|
|
137
|
-
while (part && part.next > index) {
|
|
138
|
-
index = part.next;
|
|
139
|
-
if (value[part.next] === 0x2e) {
|
|
140
|
-
index++;
|
|
141
|
-
part = NameOrIdentifier.namespacePart(value, index);
|
|
142
|
-
if (part && value[part.next] !== 0x2e) return index - 1;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return index - 1;
|
|
147
|
-
}
|
|
148
|
-
export function odataIdentifier(value: Utils.SourceArray, index: number, tokenType?: Lexer.TokenType): Lexer.Token {
|
|
149
|
-
let start = index;
|
|
150
|
-
if (Lexer.identifierLeadingCharacter(value[index])) {
|
|
151
|
-
index++;
|
|
152
|
-
while (index < value.length && (index - start < 128) && Lexer.identifierCharacter(value[index])) {
|
|
153
|
-
index++;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (index > start) return Lexer.tokenize(value, start, index, { name: Utils.stringify(value, start, index) }, tokenType || Lexer.TokenType.ODataIdentifier);
|
|
158
|
-
}
|
|
159
|
-
export function namespacePart(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.NamespacePart); }
|
|
160
|
-
export function entitySetName(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
161
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntitySetName);
|
|
162
|
-
if (!token) return;
|
|
163
|
-
|
|
164
|
-
if (typeof metadataContext === "object") {
|
|
165
|
-
let entitySet;
|
|
166
|
-
metadataContext.dataServices.schemas.forEach(schema => schema.entityContainer.forEach(container => container.entitySets.filter((set) => {
|
|
167
|
-
let eq = set.name === token.raw;
|
|
168
|
-
if (eq) entitySet = set;
|
|
169
|
-
return eq;
|
|
170
|
-
})));
|
|
171
|
-
if (!entitySet) return;
|
|
172
|
-
|
|
173
|
-
let entityType;
|
|
174
|
-
metadataContext.dataServices.schemas.forEach(schema => entitySet.entityType.indexOf(schema.namespace + ".") === 0 && schema.entityTypes.filter((type) => {
|
|
175
|
-
let eq = type.name === entitySet.entityType.replace(schema.namespace + ".", "");
|
|
176
|
-
if (eq) entityType = type;
|
|
177
|
-
return eq;
|
|
178
|
-
}));
|
|
179
|
-
if (!entityType) return;
|
|
180
|
-
|
|
181
|
-
token.metadata = entityType;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return token;
|
|
185
|
-
}
|
|
186
|
-
export function singletonEntity(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.SingletonEntity); }
|
|
187
|
-
export function entityTypeName(value: Utils.SourceArray, index: number, schema?: any): Lexer.Token {
|
|
188
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityTypeName);
|
|
189
|
-
if (!token) return;
|
|
190
|
-
|
|
191
|
-
if (typeof schema === "object") {
|
|
192
|
-
let type = schema.entityTypes.filter(it => it.name === token.raw)[0];
|
|
193
|
-
if (!type) return;
|
|
194
|
-
token.metadata = type;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return token;
|
|
198
|
-
}
|
|
199
|
-
export function complexTypeName(value: Utils.SourceArray, index: number, schema?: any): Lexer.Token {
|
|
200
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexTypeName);
|
|
201
|
-
if (!token) return;
|
|
202
|
-
|
|
203
|
-
if (typeof schema === "object") {
|
|
204
|
-
let type = schema.complexTypes.filter(it => it.name === token.raw)[0];
|
|
205
|
-
if (!type) return;
|
|
206
|
-
token.metadata = type;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return token;
|
|
210
|
-
}
|
|
211
|
-
export function typeDefinitionName(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.TypeDefinitionName); }
|
|
212
|
-
export function enumerationTypeName(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EnumerationTypeName); }
|
|
213
|
-
export function enumerationMember(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EnumerationMember); }
|
|
214
|
-
export function termName(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.TermName); }
|
|
215
|
-
export function primitiveTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
216
|
-
if (!Utils.equals(value, index, "Edm.")) return;
|
|
217
|
-
let start = index;
|
|
218
|
-
index += 4;
|
|
219
|
-
let end = index + (Utils.equals(value, index, "Binary") ||
|
|
220
|
-
Utils.equals(value, index, "Boolean") ||
|
|
221
|
-
Utils.equals(value, index, "Byte") ||
|
|
222
|
-
Utils.equals(value, index, "Date") ||
|
|
223
|
-
Utils.equals(value, index, "DateTimeOffset") ||
|
|
224
|
-
Utils.equals(value, index, "Decimal") ||
|
|
225
|
-
Utils.equals(value, index, "Double") ||
|
|
226
|
-
Utils.equals(value, index, "Duration") ||
|
|
227
|
-
Utils.equals(value, index, "Guid") ||
|
|
228
|
-
Utils.equals(value, index, "Int16") ||
|
|
229
|
-
Utils.equals(value, index, "Int32") ||
|
|
230
|
-
Utils.equals(value, index, "Int64") ||
|
|
231
|
-
Utils.equals(value, index, "SByte") ||
|
|
232
|
-
Utils.equals(value, index, "Single") ||
|
|
233
|
-
Utils.equals(value, index, "Stream") ||
|
|
234
|
-
Utils.equals(value, index, "String") ||
|
|
235
|
-
Utils.equals(value, index, "TimeOfDay") ||
|
|
236
|
-
Utils.equals(value, index, "GeographyCollection") ||
|
|
237
|
-
Utils.equals(value, index, "GeographyLineString") ||
|
|
238
|
-
Utils.equals(value, index, "GeographyMultiLineString") ||
|
|
239
|
-
Utils.equals(value, index, "GeographyMultiPoint") ||
|
|
240
|
-
Utils.equals(value, index, "GeographyMultiPolygon") ||
|
|
241
|
-
Utils.equals(value, index, "GeographyPoint") ||
|
|
242
|
-
Utils.equals(value, index, "GeographyPolygon") ||
|
|
243
|
-
Utils.equals(value, index, "GeometryCollection") ||
|
|
244
|
-
Utils.equals(value, index, "GeometryLineString") ||
|
|
245
|
-
Utils.equals(value, index, "GeometryMultiLineString") ||
|
|
246
|
-
Utils.equals(value, index, "GeometryMultiPoint") ||
|
|
247
|
-
Utils.equals(value, index, "GeometryMultiPolygon") ||
|
|
248
|
-
Utils.equals(value, index, "GeometryPoint") ||
|
|
249
|
-
Utils.equals(value, index, "GeometryPolygon")
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
if (end > index) return Lexer.tokenize(value, start, end, "PrimitiveTypeName", Lexer.TokenType.Identifier);
|
|
253
|
-
}
|
|
254
|
-
const primitiveTypes: string[] = [
|
|
255
|
-
"Edm.Binary", "Edm.Boolean", "Edm.Byte", "Edm.Date", "Edm.DateTimeOffset", "Edm.Decimal", "Edm.Double", "Edm.Duration", "Edm.Guid",
|
|
256
|
-
"Edm.Int16", "Edm.Int32", "Edm.Int64", "Edm.SByte", "Edm.Single", "Edm.Stream", "Edm.String", "Edm.Array", "Edm.TimeOfDay",
|
|
257
|
-
"Edm.GeographyCollection", "Edm.GeographyLineString", "Edm.GeographyMultiLineString", "Edm.GeographyMultiPoint", "Edm.GeographyMultiPolygon", "Edm.GeographyPoint", "Edm.GeographyPolygon",
|
|
258
|
-
"Edm.GeometryCollection", "Edm.GeometryLineString", "Edm.GeometryMultiLineString", "Edm.GeometryMultiPoint", "Edm.GeometryMultiPolygon", "Edm.GeometryPoint", "Edm.GeometryPolygon"
|
|
259
|
-
];
|
|
260
|
-
export function isPrimitiveTypeName(type: string, metadataContext?: any): boolean {
|
|
261
|
-
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
262
|
-
let schemas = root.schemas || (root.dataServices && root.dataServices.schemas) || [];
|
|
263
|
-
let schema = schemas.filter(function (it) { return type.indexOf(it.namespace + ".") === 0; })[0];
|
|
264
|
-
if (schema) {
|
|
265
|
-
return ((schema.enumTypes && schema.enumTypes.filter(function (it) { return it.name === type.split(".").pop(); })[0]) ||
|
|
266
|
-
(schema.typeDefinitions && schema.typeDefinitions.filter(function (it) { return it.name === type.split(".").pop(); })[0])) &&
|
|
267
|
-
!(
|
|
268
|
-
(schema.entityTypes && schema.entityTypes.filter(function (it) { return it.name === type.split(".").pop(); })[0]) ||
|
|
269
|
-
(schema.complexTypes && schema.complexTypes.filter(function (it) { return it.name === type.split(".").pop(); })[0])
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
return primitiveTypes.indexOf(type) >= 0;
|
|
273
|
-
}
|
|
274
|
-
export function getMetadataRoot(metadataContext: any) {
|
|
275
|
-
let root = metadataContext;
|
|
276
|
-
while (root.parent) {
|
|
277
|
-
root = root.parent;
|
|
278
|
-
}
|
|
279
|
-
return root.dataServices || root;
|
|
280
|
-
}
|
|
281
|
-
export function primitiveProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
282
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveProperty);
|
|
283
|
-
if (!token) return;
|
|
284
|
-
|
|
285
|
-
if (typeof metadataContext === "object") {
|
|
286
|
-
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
287
|
-
let prop = metadataContext.properties[i];
|
|
288
|
-
if (prop.name === token.raw) {
|
|
289
|
-
if (prop.type.indexOf("Collection") === 0 || !NameOrIdentifier.isPrimitiveTypeName(prop.type, metadataContext)) return;
|
|
290
|
-
token.metadata = prop;
|
|
291
|
-
|
|
292
|
-
if (metadataContext.key && metadataContext.key.propertyRefs.filter(it => it.name === prop.name).length > 0) {
|
|
293
|
-
token.type = Lexer.TokenType.PrimitiveKeyProperty;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (!token.metadata) return;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return token;
|
|
304
|
-
}
|
|
305
|
-
export function primitiveKeyProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
306
|
-
let token = NameOrIdentifier.primitiveProperty(value, index, metadataContext);
|
|
307
|
-
if (token && token.type === Lexer.TokenType.PrimitiveKeyProperty) return token;
|
|
308
|
-
}
|
|
309
|
-
export function primitiveNonKeyProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
310
|
-
let token = NameOrIdentifier.primitiveProperty(value, index, metadataContext);
|
|
311
|
-
if (token && token.type === Lexer.TokenType.PrimitiveProperty) return token;
|
|
312
|
-
}
|
|
313
|
-
export function primitiveColProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
314
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveCollectionProperty);
|
|
315
|
-
if (!token) return;
|
|
316
|
-
|
|
317
|
-
if (typeof metadataContext === "object") {
|
|
318
|
-
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
319
|
-
let prop = metadataContext.properties[i];
|
|
320
|
-
if (prop.name === token.raw) {
|
|
321
|
-
if (prop.type.indexOf("Collection") === -1 || !NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) return;
|
|
322
|
-
token.metadata = prop;
|
|
323
|
-
|
|
324
|
-
if (metadataContext.key.propertyRefs.filter(it => it.name === prop.name).length > 0) {
|
|
325
|
-
token.type = Lexer.TokenType.PrimitiveKeyProperty;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (!token.metadata) return;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return token;
|
|
336
|
-
}
|
|
337
|
-
export function complexProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
338
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexProperty);
|
|
339
|
-
if (!token) return;
|
|
340
|
-
|
|
341
|
-
if (typeof metadataContext === "object") {
|
|
342
|
-
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
343
|
-
let prop = metadataContext.properties[i];
|
|
344
|
-
if (prop.name === token.raw) {
|
|
345
|
-
if (prop.type.indexOf("Collection") === 0 || NameOrIdentifier.isPrimitiveTypeName(prop.type, metadataContext)) return;
|
|
346
|
-
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
347
|
-
let schema = root.schemas.filter(it => prop.type.indexOf(it.namespace + ".") === 0)[0];
|
|
348
|
-
if (!schema) return;
|
|
349
|
-
|
|
350
|
-
let complexType = schema.complexTypes.filter(it => it.name === prop.type.split(".").pop())[0];
|
|
351
|
-
if (!complexType) return;
|
|
352
|
-
|
|
353
|
-
token.metadata = complexType;
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!token.metadata) return;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return token;
|
|
362
|
-
}
|
|
363
|
-
export function complexColProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
364
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexCollectionProperty);
|
|
365
|
-
if (!token) return;
|
|
366
|
-
|
|
367
|
-
if (typeof metadataContext === "object") {
|
|
368
|
-
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
369
|
-
let prop = metadataContext.properties[i];
|
|
370
|
-
if (prop.name === token.raw) {
|
|
371
|
-
if (prop.type.indexOf("Collection") === -1 || NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) return;
|
|
372
|
-
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
373
|
-
let schema = root.schemas.filter(it => prop.type.slice(11, -1).indexOf(it.namespace + ".") === 0)[0];
|
|
374
|
-
if (!schema) return;
|
|
375
|
-
|
|
376
|
-
let complexType = schema.complexTypes.filter(it => it.name === prop.type.slice(11, -1).split(".").pop())[0];
|
|
377
|
-
if (!complexType) return;
|
|
378
|
-
|
|
379
|
-
token.metadata = complexType;
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (!token.metadata) return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return token;
|
|
388
|
-
}
|
|
389
|
-
export function streamProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
390
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.StreamProperty);
|
|
391
|
-
if (!token) return;
|
|
392
|
-
|
|
393
|
-
if (typeof metadataContext === "object") {
|
|
394
|
-
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
395
|
-
let prop = metadataContext.properties[i];
|
|
396
|
-
if (prop.name === token.raw) {
|
|
397
|
-
if (prop.type !== "Edm.Stream") return;
|
|
398
|
-
token.metadata = prop;
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (!token.metadata) return;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return token;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export function navigationProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
410
|
-
return NameOrIdentifier.entityNavigationProperty(value, index, metadataContext) ||
|
|
411
|
-
NameOrIdentifier.entityColNavigationProperty(value, index, metadataContext);
|
|
412
|
-
}
|
|
413
|
-
export function entityNavigationProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
414
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityNavigationProperty);
|
|
415
|
-
if (!token) return;
|
|
416
|
-
|
|
417
|
-
if (typeof metadataContext === "object") {
|
|
418
|
-
for (let i = 0; i < metadataContext.navigationProperties.length; i++) {
|
|
419
|
-
let prop = metadataContext.navigationProperties[i];
|
|
420
|
-
if (prop.name === token.raw && prop.type.indexOf("Collection") === -1 && !NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) {
|
|
421
|
-
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
422
|
-
let schema = root.schemas.filter(it => prop.type.indexOf(it.namespace + ".") === 0)[0];
|
|
423
|
-
if (!schema) return;
|
|
424
|
-
|
|
425
|
-
let entityType = schema.entityTypes.filter(it => it.name === prop.type.split(".").pop())[0];
|
|
426
|
-
if (!entityType) return;
|
|
427
|
-
|
|
428
|
-
token.metadata = entityType;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (!token.metadata) return;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return token;
|
|
435
|
-
}
|
|
436
|
-
export function entityColNavigationProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
437
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityCollectionNavigationProperty);
|
|
438
|
-
if (!token) return;
|
|
439
|
-
|
|
440
|
-
if (typeof metadataContext === "object") {
|
|
441
|
-
for (let i = 0; i < metadataContext.navigationProperties.length; i++) {
|
|
442
|
-
let prop = metadataContext.navigationProperties[i];
|
|
443
|
-
if (prop.name === token.raw && prop.type.indexOf("Collection") === 0 && !NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) {
|
|
444
|
-
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
445
|
-
let schema = root.schemas.filter(it => prop.type.slice(11, -1).indexOf(it.namespace + ".") === 0)[0];
|
|
446
|
-
if (!schema) return;
|
|
447
|
-
|
|
448
|
-
let entityType = schema.entityTypes.filter(it => it.name === prop.type.slice(11, -1).split(".").pop())[0];
|
|
449
|
-
if (!entityType) return;
|
|
450
|
-
|
|
451
|
-
token.metadata = entityType;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
if (!token.metadata) return;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return token;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
export function action(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
461
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.Action);
|
|
462
|
-
if (!token) return;
|
|
463
|
-
|
|
464
|
-
if (typeof metadataContext === "object") {
|
|
465
|
-
let type = NameOrIdentifier.getOperationType("action", metadataContext, token, isCollection, false, false, "entityTypes");
|
|
466
|
-
if (!type) return;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return token;
|
|
470
|
-
}
|
|
471
|
-
export function actionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
472
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ActionImport);
|
|
473
|
-
if (!token) return;
|
|
474
|
-
|
|
475
|
-
if (typeof metadataContext === "object") {
|
|
476
|
-
let type = NameOrIdentifier.getOperationImportType("action", metadataContext, token);
|
|
477
|
-
if (!type) return;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return token;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
export function odataFunction(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
484
|
-
return NameOrIdentifier.entityFunction(value, index) ||
|
|
485
|
-
NameOrIdentifier.entityColFunction(value, index) ||
|
|
486
|
-
NameOrIdentifier.complexFunction(value, index) ||
|
|
487
|
-
NameOrIdentifier.complexColFunction(value, index) ||
|
|
488
|
-
NameOrIdentifier.primitiveFunction(value, index) ||
|
|
489
|
-
NameOrIdentifier.primitiveColFunction(value, index);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
export function getOperationType(operation: string, metadataContext: any, token: Lexer.Token, isBoundCollection: boolean, isCollection: boolean, isPrimitive: boolean, types?: string) {
|
|
493
|
-
let bindingParameterType = metadataContext.parent.namespace + "." + metadataContext.name;
|
|
494
|
-
if (isBoundCollection) bindingParameterType = "Collection(" + bindingParameterType + ")";
|
|
495
|
-
|
|
496
|
-
let fnDef;
|
|
497
|
-
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
498
|
-
for (let i = 0; i < root.schemas.length; i++) {
|
|
499
|
-
let schema = root.schemas[i];
|
|
500
|
-
for (let j = 0; j < schema[operation + "s"].length; j++) {
|
|
501
|
-
let fn = schema[operation + "s"][j];
|
|
502
|
-
if (fn.name === token.raw && fn.isBound) {
|
|
503
|
-
for (let k = 0; k < fn.parameters.length; k++) {
|
|
504
|
-
let param = fn.parameters[k];
|
|
505
|
-
if (param.name === "bindingParameter" && param.type === bindingParameterType) {
|
|
506
|
-
fnDef = fn;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
if (fnDef) break;
|
|
512
|
-
}
|
|
513
|
-
if (fnDef) break;
|
|
514
|
-
}
|
|
515
|
-
if (!fnDef) return;
|
|
516
|
-
|
|
517
|
-
if (operation === "action") return fnDef;
|
|
518
|
-
|
|
519
|
-
if (fnDef.returnType.type.indexOf("Collection") === isCollection ? -1 : 0) return;
|
|
520
|
-
let elementType = isCollection ? fnDef.returnType.type.slice(11, -1) : fnDef.returnType.type;
|
|
521
|
-
if (NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && !isPrimitive) return;
|
|
522
|
-
if (!NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && isPrimitive) return;
|
|
523
|
-
if (isPrimitive) return elementType;
|
|
524
|
-
|
|
525
|
-
let type;
|
|
526
|
-
for (let i = 0; i < root.schemas.length; i++) {
|
|
527
|
-
let schema = root.schemas[i];
|
|
528
|
-
if (elementType.indexOf(schema.namespace + ".") === 0) {
|
|
529
|
-
for (let j = 0; j < schema[types].length; j++) {
|
|
530
|
-
let it = schema[types][j];
|
|
531
|
-
if (schema.namespace + "." + it.name === elementType) {
|
|
532
|
-
type = it;
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
if (type) break;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
return type;
|
|
541
|
-
}
|
|
542
|
-
export function entityFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
543
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityFunction);
|
|
544
|
-
if (!token) return;
|
|
545
|
-
|
|
546
|
-
if (typeof metadataContext === "object") {
|
|
547
|
-
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, false, false, "entityTypes");
|
|
548
|
-
if (!type) return;
|
|
549
|
-
token.metadata = type;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return token;
|
|
553
|
-
}
|
|
554
|
-
export function entityColFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
555
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityCollectionFunction);
|
|
556
|
-
if (!token) return;
|
|
557
|
-
|
|
558
|
-
if (typeof metadataContext === "object") {
|
|
559
|
-
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, true, false, "entityTypes");
|
|
560
|
-
if (!type) return;
|
|
561
|
-
token.metadata = type;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return token;
|
|
565
|
-
}
|
|
566
|
-
export function complexFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
567
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexFunction);
|
|
568
|
-
if (!token) return;
|
|
569
|
-
|
|
570
|
-
if (typeof metadataContext === "object") {
|
|
571
|
-
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, false, false, "complexTypes");
|
|
572
|
-
if (!type) return;
|
|
573
|
-
token.metadata = type;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return token;
|
|
577
|
-
}
|
|
578
|
-
export function complexColFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
579
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexCollectionFunction);
|
|
580
|
-
if (!token) return;
|
|
581
|
-
|
|
582
|
-
if (typeof metadataContext === "object") {
|
|
583
|
-
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, true, false, "complexTypes");
|
|
584
|
-
if (!type) return;
|
|
585
|
-
token.metadata = type;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
return token;
|
|
589
|
-
}
|
|
590
|
-
export function primitiveFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
591
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveFunction);
|
|
592
|
-
if (!token) return;
|
|
593
|
-
|
|
594
|
-
if (typeof metadataContext === "object") {
|
|
595
|
-
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, false, true);
|
|
596
|
-
if (!type) return;
|
|
597
|
-
token.metadata = type;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
return token;
|
|
601
|
-
}
|
|
602
|
-
export function primitiveColFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
603
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveCollectionFunction);
|
|
604
|
-
if (!token) return;
|
|
605
|
-
|
|
606
|
-
if (typeof metadataContext === "object") {
|
|
607
|
-
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, true, true);
|
|
608
|
-
if (!type) return;
|
|
609
|
-
token.metadata = type;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
return token;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
export function getOperationImportType(operation: string, metadataContext: any, token: Lexer.Token, isCollection?: boolean, isPrimitive?: boolean, types?: string) {
|
|
616
|
-
let fnImport;
|
|
617
|
-
|
|
618
|
-
for (let i = 0; i < metadataContext.dataServices.schemas.length; i++) {
|
|
619
|
-
let schema = metadataContext.dataServices.schemas[i];
|
|
620
|
-
for (let j = 0; j < schema.entityContainer.length; j++) {
|
|
621
|
-
let container = schema.entityContainer[j];
|
|
622
|
-
for (let k = 0; k < container[operation + "Imports"].length; k++) {
|
|
623
|
-
let it = container[operation + "Imports"][k];
|
|
624
|
-
if (it.name === token.raw) {
|
|
625
|
-
fnImport = it;
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if (fnImport) break;
|
|
630
|
-
}
|
|
631
|
-
if (fnImport) break;
|
|
632
|
-
}
|
|
633
|
-
if (!fnImport) return;
|
|
634
|
-
|
|
635
|
-
let fn;
|
|
636
|
-
for (let i = 0; i < metadataContext.dataServices.schemas.length; i++) {
|
|
637
|
-
let schema = metadataContext.dataServices.schemas[i];
|
|
638
|
-
if (fnImport[operation].indexOf(schema.namespace + ".") === 0) {
|
|
639
|
-
for (let j = 0; j < schema[operation + "s"].length; j++) {
|
|
640
|
-
let it = schema[operation + "s"][j];
|
|
641
|
-
if (it.name === fnImport.name) {
|
|
642
|
-
fn = it;
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
if (fn) break;
|
|
648
|
-
}
|
|
649
|
-
if (!fn) return;
|
|
650
|
-
|
|
651
|
-
if (operation === "action") return fn;
|
|
652
|
-
if (fn.returnType.type.indexOf("Collection") === isCollection ? -1 : 0) return;
|
|
653
|
-
let elementType = isCollection ? fn.returnType.type.slice(11, -1) : fn.returnType.type;
|
|
654
|
-
if (NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && !isPrimitive) return;
|
|
655
|
-
if (!NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && isPrimitive) return;
|
|
656
|
-
if (isPrimitive) return elementType;
|
|
657
|
-
|
|
658
|
-
let type;
|
|
659
|
-
for (let i = 0; i < metadataContext.dataServices.schemas.length; i++) {
|
|
660
|
-
let schema = metadataContext.dataServices.schemas[i];
|
|
661
|
-
if (elementType.indexOf(schema.namespace + ".") === 0) {
|
|
662
|
-
for (let j = 0; j < schema[types].length; j++) {
|
|
663
|
-
let it = schema[types][j];
|
|
664
|
-
if (schema.namespace + "." + it.name === elementType) {
|
|
665
|
-
type = it;
|
|
666
|
-
break;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if (type) break;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
return type;
|
|
674
|
-
}
|
|
675
|
-
export function entityFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
676
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityFunctionImport);
|
|
677
|
-
if (!token) return;
|
|
678
|
-
|
|
679
|
-
if (typeof metadataContext === "object") {
|
|
680
|
-
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, false, false, "entityTypes");
|
|
681
|
-
if (!type) return;
|
|
682
|
-
token.metadata = type;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
return token;
|
|
686
|
-
}
|
|
687
|
-
export function entityColFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
688
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityCollectionFunctionImport);
|
|
689
|
-
if (!token) return;
|
|
690
|
-
|
|
691
|
-
if (typeof metadataContext === "object") {
|
|
692
|
-
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, true, false, "entityTypes");
|
|
693
|
-
if (!type) return;
|
|
694
|
-
token.metadata = type;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
return token;
|
|
698
|
-
}
|
|
699
|
-
export function complexFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
700
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexFunctionImport);
|
|
701
|
-
if (!token) return;
|
|
702
|
-
|
|
703
|
-
if (typeof metadataContext === "object") {
|
|
704
|
-
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, false, false, "complexTypes");
|
|
705
|
-
if (!type) return;
|
|
706
|
-
token.metadata = type;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
return token;
|
|
710
|
-
}
|
|
711
|
-
export function complexColFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
712
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexCollectionFunctionImport);
|
|
713
|
-
if (!token) return;
|
|
714
|
-
|
|
715
|
-
if (typeof metadataContext === "object") {
|
|
716
|
-
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, true, false, "complexTypes");
|
|
717
|
-
if (!type) return;
|
|
718
|
-
token.metadata = type;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
return token;
|
|
722
|
-
}
|
|
723
|
-
export function primitiveFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
724
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveFunctionImport);
|
|
725
|
-
if (!token) return;
|
|
726
|
-
|
|
727
|
-
if (typeof metadataContext === "object") {
|
|
728
|
-
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, false, true);
|
|
729
|
-
if (!type) return;
|
|
730
|
-
token.metadata = type;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
return token;
|
|
734
|
-
}
|
|
735
|
-
export function primitiveColFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
736
|
-
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveCollectionFunctionImport);
|
|
737
|
-
if (!token) return;
|
|
738
|
-
|
|
739
|
-
if (typeof metadataContext === "object") {
|
|
740
|
-
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, true, true);
|
|
741
|
-
if (!type) return;
|
|
742
|
-
token.metadata = type;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
return token;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
|
|
1
|
+
import Utils from "./utils";
|
|
2
|
+
import Lexer from "./lexer";
|
|
3
|
+
import PrimitiveLiteral from "./primitiveLiteral";
|
|
4
|
+
|
|
5
|
+
export namespace NameOrIdentifier {
|
|
6
|
+
export function enumeration(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
7
|
+
let type = qualifiedEnumTypeName(value, index);
|
|
8
|
+
if (!type) return;
|
|
9
|
+
let start = index;
|
|
10
|
+
index = type.next;
|
|
11
|
+
|
|
12
|
+
let squote = Lexer.SQUOTE(value, index);
|
|
13
|
+
if (!squote) return;
|
|
14
|
+
index = squote;
|
|
15
|
+
|
|
16
|
+
let enumVal = NameOrIdentifier.enumValue(value, index);
|
|
17
|
+
if (!enumVal) return;
|
|
18
|
+
index = enumVal.next;
|
|
19
|
+
|
|
20
|
+
squote = Lexer.SQUOTE(value, index);
|
|
21
|
+
if (!squote) return;
|
|
22
|
+
index = squote;
|
|
23
|
+
|
|
24
|
+
return Lexer.tokenize(value, start, index, {
|
|
25
|
+
name: type,
|
|
26
|
+
value: enumVal
|
|
27
|
+
}, Lexer.TokenType.Enum);
|
|
28
|
+
}
|
|
29
|
+
export function enumValue(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
30
|
+
let val = NameOrIdentifier.singleEnumValue(value, index);
|
|
31
|
+
if (!val) return;
|
|
32
|
+
let start = index;
|
|
33
|
+
|
|
34
|
+
let arr = [];
|
|
35
|
+
while (val) {
|
|
36
|
+
arr.push(val);
|
|
37
|
+
index = val.next;
|
|
38
|
+
let comma = Lexer.COMMA(value, val.next);
|
|
39
|
+
if (comma) {
|
|
40
|
+
index = comma;
|
|
41
|
+
val = NameOrIdentifier.singleEnumValue(value, index);
|
|
42
|
+
}else break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Lexer.tokenize(value, start, index, { values: arr }, Lexer.TokenType.EnumValue);
|
|
46
|
+
}
|
|
47
|
+
export function singleEnumValue(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
48
|
+
return NameOrIdentifier.enumerationMember(value, index) ||
|
|
49
|
+
NameOrIdentifier.enumMemberValue(value, index);
|
|
50
|
+
}
|
|
51
|
+
export function enumMemberValue(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
52
|
+
let token = PrimitiveLiteral.int64Value(value, index);
|
|
53
|
+
if (token) {
|
|
54
|
+
token.type = Lexer.TokenType.EnumMemberValue;
|
|
55
|
+
return token;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function singleQualifiedTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
59
|
+
return NameOrIdentifier.qualifiedEntityTypeName(value, index) ||
|
|
60
|
+
NameOrIdentifier.qualifiedComplexTypeName(value, index) ||
|
|
61
|
+
NameOrIdentifier.qualifiedTypeDefinitionName(value, index) ||
|
|
62
|
+
NameOrIdentifier.qualifiedEnumTypeName(value, index) ||
|
|
63
|
+
NameOrIdentifier.primitiveTypeName(value, index);
|
|
64
|
+
}
|
|
65
|
+
export function qualifiedTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
66
|
+
if (Utils.equals(value, index, "Collection")) {
|
|
67
|
+
let start = index;
|
|
68
|
+
index += 10;
|
|
69
|
+
|
|
70
|
+
let squote = Lexer.SQUOTE(value, index);
|
|
71
|
+
if (!squote) return;
|
|
72
|
+
index = squote;
|
|
73
|
+
|
|
74
|
+
let token = NameOrIdentifier.singleQualifiedTypeName(value, index);
|
|
75
|
+
if (!token) return;
|
|
76
|
+
else index = token.next;
|
|
77
|
+
|
|
78
|
+
squote = Lexer.SQUOTE(value, index);
|
|
79
|
+
if (!squote) return;
|
|
80
|
+
index = squote;
|
|
81
|
+
|
|
82
|
+
token.position = start;
|
|
83
|
+
token.next = index;
|
|
84
|
+
token.raw = Utils.stringify(value, token.position, token.next);
|
|
85
|
+
token.type = Lexer.TokenType.Collection;
|
|
86
|
+
} else return NameOrIdentifier.singleQualifiedTypeName(value, index);
|
|
87
|
+
}
|
|
88
|
+
export function qualifiedEntityTypeName(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
89
|
+
let start = index;
|
|
90
|
+
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
91
|
+
|
|
92
|
+
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
93
|
+
let schema;
|
|
94
|
+
if (typeof metadataContext === "object") {
|
|
95
|
+
schema = NameOrIdentifier.getMetadataRoot(metadataContext).schemas.filter(it => it.namespace === Utils.stringify(value, start, namespaceNext))[0];
|
|
96
|
+
}
|
|
97
|
+
let name = NameOrIdentifier.entityTypeName(value, namespaceNext + 1, schema);
|
|
98
|
+
if (!name) return;
|
|
99
|
+
name.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
100
|
+
|
|
101
|
+
return Lexer.tokenize(value, start, name.next, name, Lexer.TokenType.QualifiedEntityTypeName);
|
|
102
|
+
}
|
|
103
|
+
export function qualifiedComplexTypeName(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
104
|
+
let start = index;
|
|
105
|
+
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
106
|
+
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
107
|
+
let schema;
|
|
108
|
+
if (typeof metadataContext === "object") {
|
|
109
|
+
schema = NameOrIdentifier.getMetadataRoot(metadataContext).schemas.filter(it => it.namespace === Utils.stringify(value, start, namespaceNext))[0];
|
|
110
|
+
}
|
|
111
|
+
let name = NameOrIdentifier.complexTypeName(value, namespaceNext + 1, schema);
|
|
112
|
+
if (!name) return;
|
|
113
|
+
name.value.namespace = Utils.stringify(value, start, namespaceNext);
|
|
114
|
+
|
|
115
|
+
return Lexer.tokenize(value, start, name.next, name, Lexer.TokenType.QualifiedComplexTypeName);
|
|
116
|
+
}
|
|
117
|
+
export function qualifiedTypeDefinitionName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
118
|
+
let start = index;
|
|
119
|
+
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
120
|
+
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
121
|
+
let nameNext = NameOrIdentifier.typeDefinitionName(value, namespaceNext + 1);
|
|
122
|
+
if (nameNext && nameNext.next === namespaceNext + 1) return;
|
|
123
|
+
|
|
124
|
+
return Lexer.tokenize(value, start, nameNext.next, "TypeDefinitionName", Lexer.TokenType.Identifier);
|
|
125
|
+
}
|
|
126
|
+
export function qualifiedEnumTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
127
|
+
let start = index;
|
|
128
|
+
let namespaceNext = NameOrIdentifier.namespace(value, index);
|
|
129
|
+
if (namespaceNext === index || value[namespaceNext] !== 0x2e) return;
|
|
130
|
+
let nameNext = NameOrIdentifier.enumerationTypeName(value, namespaceNext + 1);
|
|
131
|
+
if (nameNext && nameNext.next === namespaceNext + 1) return;
|
|
132
|
+
|
|
133
|
+
return Lexer.tokenize(value, start, nameNext.next, "EnumTypeName", Lexer.TokenType.Identifier);
|
|
134
|
+
}
|
|
135
|
+
export function namespace(value: Utils.SourceArray, index: number): number {
|
|
136
|
+
let part = NameOrIdentifier.namespacePart(value, index);
|
|
137
|
+
while (part && part.next > index) {
|
|
138
|
+
index = part.next;
|
|
139
|
+
if (value[part.next] === 0x2e) {
|
|
140
|
+
index++;
|
|
141
|
+
part = NameOrIdentifier.namespacePart(value, index);
|
|
142
|
+
if (part && value[part.next] !== 0x2e) return index - 1;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return index - 1;
|
|
147
|
+
}
|
|
148
|
+
export function odataIdentifier(value: Utils.SourceArray, index: number, tokenType?: Lexer.TokenType): Lexer.Token {
|
|
149
|
+
let start = index;
|
|
150
|
+
if (Lexer.identifierLeadingCharacter(value[index])) {
|
|
151
|
+
index++;
|
|
152
|
+
while (index < value.length && (index - start < 128) && Lexer.identifierCharacter(value[index])) {
|
|
153
|
+
index++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (index > start) return Lexer.tokenize(value, start, index, { name: Utils.stringify(value, start, index) }, tokenType || Lexer.TokenType.ODataIdentifier);
|
|
158
|
+
}
|
|
159
|
+
export function namespacePart(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.NamespacePart); }
|
|
160
|
+
export function entitySetName(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
161
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntitySetName);
|
|
162
|
+
if (!token) return;
|
|
163
|
+
|
|
164
|
+
if (typeof metadataContext === "object") {
|
|
165
|
+
let entitySet;
|
|
166
|
+
metadataContext.dataServices.schemas.forEach(schema => schema.entityContainer.forEach(container => container.entitySets.filter((set) => {
|
|
167
|
+
let eq = set.name === token.raw;
|
|
168
|
+
if (eq) entitySet = set;
|
|
169
|
+
return eq;
|
|
170
|
+
})));
|
|
171
|
+
if (!entitySet) return;
|
|
172
|
+
|
|
173
|
+
let entityType;
|
|
174
|
+
metadataContext.dataServices.schemas.forEach(schema => entitySet.entityType.indexOf(schema.namespace + ".") === 0 && schema.entityTypes.filter((type) => {
|
|
175
|
+
let eq = type.name === entitySet.entityType.replace(schema.namespace + ".", "");
|
|
176
|
+
if (eq) entityType = type;
|
|
177
|
+
return eq;
|
|
178
|
+
}));
|
|
179
|
+
if (!entityType) return;
|
|
180
|
+
|
|
181
|
+
token.metadata = entityType;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return token;
|
|
185
|
+
}
|
|
186
|
+
export function singletonEntity(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.SingletonEntity); }
|
|
187
|
+
export function entityTypeName(value: Utils.SourceArray, index: number, schema?: any): Lexer.Token {
|
|
188
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityTypeName);
|
|
189
|
+
if (!token) return;
|
|
190
|
+
|
|
191
|
+
if (typeof schema === "object") {
|
|
192
|
+
let type = schema.entityTypes.filter(it => it.name === token.raw)[0];
|
|
193
|
+
if (!type) return;
|
|
194
|
+
token.metadata = type;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return token;
|
|
198
|
+
}
|
|
199
|
+
export function complexTypeName(value: Utils.SourceArray, index: number, schema?: any): Lexer.Token {
|
|
200
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexTypeName);
|
|
201
|
+
if (!token) return;
|
|
202
|
+
|
|
203
|
+
if (typeof schema === "object") {
|
|
204
|
+
let type = schema.complexTypes.filter(it => it.name === token.raw)[0];
|
|
205
|
+
if (!type) return;
|
|
206
|
+
token.metadata = type;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return token;
|
|
210
|
+
}
|
|
211
|
+
export function typeDefinitionName(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.TypeDefinitionName); }
|
|
212
|
+
export function enumerationTypeName(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EnumerationTypeName); }
|
|
213
|
+
export function enumerationMember(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EnumerationMember); }
|
|
214
|
+
export function termName(value: Utils.SourceArray, index: number): Lexer.Token { return NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.TermName); }
|
|
215
|
+
export function primitiveTypeName(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
216
|
+
if (!Utils.equals(value, index, "Edm.")) return;
|
|
217
|
+
let start = index;
|
|
218
|
+
index += 4;
|
|
219
|
+
let end = index + (Utils.equals(value, index, "Binary") ||
|
|
220
|
+
Utils.equals(value, index, "Boolean") ||
|
|
221
|
+
Utils.equals(value, index, "Byte") ||
|
|
222
|
+
Utils.equals(value, index, "Date") ||
|
|
223
|
+
Utils.equals(value, index, "DateTimeOffset") ||
|
|
224
|
+
Utils.equals(value, index, "Decimal") ||
|
|
225
|
+
Utils.equals(value, index, "Double") ||
|
|
226
|
+
Utils.equals(value, index, "Duration") ||
|
|
227
|
+
Utils.equals(value, index, "Guid") ||
|
|
228
|
+
Utils.equals(value, index, "Int16") ||
|
|
229
|
+
Utils.equals(value, index, "Int32") ||
|
|
230
|
+
Utils.equals(value, index, "Int64") ||
|
|
231
|
+
Utils.equals(value, index, "SByte") ||
|
|
232
|
+
Utils.equals(value, index, "Single") ||
|
|
233
|
+
Utils.equals(value, index, "Stream") ||
|
|
234
|
+
Utils.equals(value, index, "String") ||
|
|
235
|
+
Utils.equals(value, index, "TimeOfDay") ||
|
|
236
|
+
Utils.equals(value, index, "GeographyCollection") ||
|
|
237
|
+
Utils.equals(value, index, "GeographyLineString") ||
|
|
238
|
+
Utils.equals(value, index, "GeographyMultiLineString") ||
|
|
239
|
+
Utils.equals(value, index, "GeographyMultiPoint") ||
|
|
240
|
+
Utils.equals(value, index, "GeographyMultiPolygon") ||
|
|
241
|
+
Utils.equals(value, index, "GeographyPoint") ||
|
|
242
|
+
Utils.equals(value, index, "GeographyPolygon") ||
|
|
243
|
+
Utils.equals(value, index, "GeometryCollection") ||
|
|
244
|
+
Utils.equals(value, index, "GeometryLineString") ||
|
|
245
|
+
Utils.equals(value, index, "GeometryMultiLineString") ||
|
|
246
|
+
Utils.equals(value, index, "GeometryMultiPoint") ||
|
|
247
|
+
Utils.equals(value, index, "GeometryMultiPolygon") ||
|
|
248
|
+
Utils.equals(value, index, "GeometryPoint") ||
|
|
249
|
+
Utils.equals(value, index, "GeometryPolygon")
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
if (end > index) return Lexer.tokenize(value, start, end, "PrimitiveTypeName", Lexer.TokenType.Identifier);
|
|
253
|
+
}
|
|
254
|
+
const primitiveTypes: string[] = [
|
|
255
|
+
"Edm.Binary", "Edm.Boolean", "Edm.Byte", "Edm.Date", "Edm.DateTimeOffset", "Edm.Decimal", "Edm.Double", "Edm.Duration", "Edm.Guid",
|
|
256
|
+
"Edm.Int16", "Edm.Int32", "Edm.Int64", "Edm.SByte", "Edm.Single", "Edm.Stream", "Edm.String", "Edm.Array", "Edm.TimeOfDay",
|
|
257
|
+
"Edm.GeographyCollection", "Edm.GeographyLineString", "Edm.GeographyMultiLineString", "Edm.GeographyMultiPoint", "Edm.GeographyMultiPolygon", "Edm.GeographyPoint", "Edm.GeographyPolygon",
|
|
258
|
+
"Edm.GeometryCollection", "Edm.GeometryLineString", "Edm.GeometryMultiLineString", "Edm.GeometryMultiPoint", "Edm.GeometryMultiPolygon", "Edm.GeometryPoint", "Edm.GeometryPolygon"
|
|
259
|
+
];
|
|
260
|
+
export function isPrimitiveTypeName(type: string, metadataContext?: any): boolean {
|
|
261
|
+
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
262
|
+
let schemas = root.schemas || (root.dataServices && root.dataServices.schemas) || [];
|
|
263
|
+
let schema = schemas.filter(function (it) { return type.indexOf(it.namespace + ".") === 0; })[0];
|
|
264
|
+
if (schema) {
|
|
265
|
+
return ((schema.enumTypes && schema.enumTypes.filter(function (it) { return it.name === type.split(".").pop(); })[0]) ||
|
|
266
|
+
(schema.typeDefinitions && schema.typeDefinitions.filter(function (it) { return it.name === type.split(".").pop(); })[0])) &&
|
|
267
|
+
!(
|
|
268
|
+
(schema.entityTypes && schema.entityTypes.filter(function (it) { return it.name === type.split(".").pop(); })[0]) ||
|
|
269
|
+
(schema.complexTypes && schema.complexTypes.filter(function (it) { return it.name === type.split(".").pop(); })[0])
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
return primitiveTypes.indexOf(type) >= 0;
|
|
273
|
+
}
|
|
274
|
+
export function getMetadataRoot(metadataContext: any) {
|
|
275
|
+
let root = metadataContext;
|
|
276
|
+
while (root.parent) {
|
|
277
|
+
root = root.parent;
|
|
278
|
+
}
|
|
279
|
+
return root.dataServices || root;
|
|
280
|
+
}
|
|
281
|
+
export function primitiveProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
282
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveProperty);
|
|
283
|
+
if (!token) return;
|
|
284
|
+
|
|
285
|
+
if (typeof metadataContext === "object") {
|
|
286
|
+
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
287
|
+
let prop = metadataContext.properties[i];
|
|
288
|
+
if (prop.name === token.raw) {
|
|
289
|
+
if (prop.type.indexOf("Collection") === 0 || !NameOrIdentifier.isPrimitiveTypeName(prop.type, metadataContext)) return;
|
|
290
|
+
token.metadata = prop;
|
|
291
|
+
|
|
292
|
+
if (metadataContext.key && metadataContext.key.propertyRefs.filter(it => it.name === prop.name).length > 0) {
|
|
293
|
+
token.type = Lexer.TokenType.PrimitiveKeyProperty;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (!token.metadata) return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return token;
|
|
304
|
+
}
|
|
305
|
+
export function primitiveKeyProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
306
|
+
let token = NameOrIdentifier.primitiveProperty(value, index, metadataContext);
|
|
307
|
+
if (token && token.type === Lexer.TokenType.PrimitiveKeyProperty) return token;
|
|
308
|
+
}
|
|
309
|
+
export function primitiveNonKeyProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
310
|
+
let token = NameOrIdentifier.primitiveProperty(value, index, metadataContext);
|
|
311
|
+
if (token && token.type === Lexer.TokenType.PrimitiveProperty) return token;
|
|
312
|
+
}
|
|
313
|
+
export function primitiveColProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
314
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveCollectionProperty);
|
|
315
|
+
if (!token) return;
|
|
316
|
+
|
|
317
|
+
if (typeof metadataContext === "object") {
|
|
318
|
+
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
319
|
+
let prop = metadataContext.properties[i];
|
|
320
|
+
if (prop.name === token.raw) {
|
|
321
|
+
if (prop.type.indexOf("Collection") === -1 || !NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) return;
|
|
322
|
+
token.metadata = prop;
|
|
323
|
+
|
|
324
|
+
if (metadataContext.key.propertyRefs.filter(it => it.name === prop.name).length > 0) {
|
|
325
|
+
token.type = Lexer.TokenType.PrimitiveKeyProperty;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!token.metadata) return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return token;
|
|
336
|
+
}
|
|
337
|
+
export function complexProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
338
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexProperty);
|
|
339
|
+
if (!token) return;
|
|
340
|
+
|
|
341
|
+
if (typeof metadataContext === "object") {
|
|
342
|
+
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
343
|
+
let prop = metadataContext.properties[i];
|
|
344
|
+
if (prop.name === token.raw) {
|
|
345
|
+
if (prop.type.indexOf("Collection") === 0 || NameOrIdentifier.isPrimitiveTypeName(prop.type, metadataContext)) return;
|
|
346
|
+
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
347
|
+
let schema = root.schemas.filter(it => prop.type.indexOf(it.namespace + ".") === 0)[0];
|
|
348
|
+
if (!schema) return;
|
|
349
|
+
|
|
350
|
+
let complexType = schema.complexTypes.filter(it => it.name === prop.type.split(".").pop())[0];
|
|
351
|
+
if (!complexType) return;
|
|
352
|
+
|
|
353
|
+
token.metadata = complexType;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (!token.metadata) return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return token;
|
|
362
|
+
}
|
|
363
|
+
export function complexColProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
364
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexCollectionProperty);
|
|
365
|
+
if (!token) return;
|
|
366
|
+
|
|
367
|
+
if (typeof metadataContext === "object") {
|
|
368
|
+
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
369
|
+
let prop = metadataContext.properties[i];
|
|
370
|
+
if (prop.name === token.raw) {
|
|
371
|
+
if (prop.type.indexOf("Collection") === -1 || NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) return;
|
|
372
|
+
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
373
|
+
let schema = root.schemas.filter(it => prop.type.slice(11, -1).indexOf(it.namespace + ".") === 0)[0];
|
|
374
|
+
if (!schema) return;
|
|
375
|
+
|
|
376
|
+
let complexType = schema.complexTypes.filter(it => it.name === prop.type.slice(11, -1).split(".").pop())[0];
|
|
377
|
+
if (!complexType) return;
|
|
378
|
+
|
|
379
|
+
token.metadata = complexType;
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (!token.metadata) return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return token;
|
|
388
|
+
}
|
|
389
|
+
export function streamProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
390
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.StreamProperty);
|
|
391
|
+
if (!token) return;
|
|
392
|
+
|
|
393
|
+
if (typeof metadataContext === "object") {
|
|
394
|
+
for (let i = 0; i < metadataContext.properties.length; i++) {
|
|
395
|
+
let prop = metadataContext.properties[i];
|
|
396
|
+
if (prop.name === token.raw) {
|
|
397
|
+
if (prop.type !== "Edm.Stream") return;
|
|
398
|
+
token.metadata = prop;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (!token.metadata) return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return token;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function navigationProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
410
|
+
return NameOrIdentifier.entityNavigationProperty(value, index, metadataContext) ||
|
|
411
|
+
NameOrIdentifier.entityColNavigationProperty(value, index, metadataContext);
|
|
412
|
+
}
|
|
413
|
+
export function entityNavigationProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
414
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityNavigationProperty);
|
|
415
|
+
if (!token) return;
|
|
416
|
+
|
|
417
|
+
if (typeof metadataContext === "object") {
|
|
418
|
+
for (let i = 0; i < metadataContext.navigationProperties.length; i++) {
|
|
419
|
+
let prop = metadataContext.navigationProperties[i];
|
|
420
|
+
if (prop.name === token.raw && prop.type.indexOf("Collection") === -1 && !NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) {
|
|
421
|
+
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
422
|
+
let schema = root.schemas.filter(it => prop.type.indexOf(it.namespace + ".") === 0)[0];
|
|
423
|
+
if (!schema) return;
|
|
424
|
+
|
|
425
|
+
let entityType = schema.entityTypes.filter(it => it.name === prop.type.split(".").pop())[0];
|
|
426
|
+
if (!entityType) return;
|
|
427
|
+
|
|
428
|
+
token.metadata = entityType;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (!token.metadata) return;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return token;
|
|
435
|
+
}
|
|
436
|
+
export function entityColNavigationProperty(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
437
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityCollectionNavigationProperty);
|
|
438
|
+
if (!token) return;
|
|
439
|
+
|
|
440
|
+
if (typeof metadataContext === "object") {
|
|
441
|
+
for (let i = 0; i < metadataContext.navigationProperties.length; i++) {
|
|
442
|
+
let prop = metadataContext.navigationProperties[i];
|
|
443
|
+
if (prop.name === token.raw && prop.type.indexOf("Collection") === 0 && !NameOrIdentifier.isPrimitiveTypeName(prop.type.slice(11, -1), metadataContext)) {
|
|
444
|
+
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
445
|
+
let schema = root.schemas.filter(it => prop.type.slice(11, -1).indexOf(it.namespace + ".") === 0)[0];
|
|
446
|
+
if (!schema) return;
|
|
447
|
+
|
|
448
|
+
let entityType = schema.entityTypes.filter(it => it.name === prop.type.slice(11, -1).split(".").pop())[0];
|
|
449
|
+
if (!entityType) return;
|
|
450
|
+
|
|
451
|
+
token.metadata = entityType;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (!token.metadata) return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return token;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export function action(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
461
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.Action);
|
|
462
|
+
if (!token) return;
|
|
463
|
+
|
|
464
|
+
if (typeof metadataContext === "object") {
|
|
465
|
+
let type = NameOrIdentifier.getOperationType("action", metadataContext, token, isCollection, false, false, "entityTypes");
|
|
466
|
+
if (!type) return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return token;
|
|
470
|
+
}
|
|
471
|
+
export function actionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
472
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ActionImport);
|
|
473
|
+
if (!token) return;
|
|
474
|
+
|
|
475
|
+
if (typeof metadataContext === "object") {
|
|
476
|
+
let type = NameOrIdentifier.getOperationImportType("action", metadataContext, token);
|
|
477
|
+
if (!type) return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return token;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export function odataFunction(value: Utils.SourceArray, index: number): Lexer.Token {
|
|
484
|
+
return NameOrIdentifier.entityFunction(value, index) ||
|
|
485
|
+
NameOrIdentifier.entityColFunction(value, index) ||
|
|
486
|
+
NameOrIdentifier.complexFunction(value, index) ||
|
|
487
|
+
NameOrIdentifier.complexColFunction(value, index) ||
|
|
488
|
+
NameOrIdentifier.primitiveFunction(value, index) ||
|
|
489
|
+
NameOrIdentifier.primitiveColFunction(value, index);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export function getOperationType(operation: string, metadataContext: any, token: Lexer.Token, isBoundCollection: boolean, isCollection: boolean, isPrimitive: boolean, types?: string) {
|
|
493
|
+
let bindingParameterType = metadataContext.parent.namespace + "." + metadataContext.name;
|
|
494
|
+
if (isBoundCollection) bindingParameterType = "Collection(" + bindingParameterType + ")";
|
|
495
|
+
|
|
496
|
+
let fnDef;
|
|
497
|
+
let root = NameOrIdentifier.getMetadataRoot(metadataContext);
|
|
498
|
+
for (let i = 0; i < root.schemas.length; i++) {
|
|
499
|
+
let schema = root.schemas[i];
|
|
500
|
+
for (let j = 0; j < schema[operation + "s"].length; j++) {
|
|
501
|
+
let fn = schema[operation + "s"][j];
|
|
502
|
+
if (fn.name === token.raw && fn.isBound) {
|
|
503
|
+
for (let k = 0; k < fn.parameters.length; k++) {
|
|
504
|
+
let param = fn.parameters[k];
|
|
505
|
+
if (param.name === "bindingParameter" && param.type === bindingParameterType) {
|
|
506
|
+
fnDef = fn;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (fnDef) break;
|
|
512
|
+
}
|
|
513
|
+
if (fnDef) break;
|
|
514
|
+
}
|
|
515
|
+
if (!fnDef) return;
|
|
516
|
+
|
|
517
|
+
if (operation === "action") return fnDef;
|
|
518
|
+
|
|
519
|
+
if (fnDef.returnType.type.indexOf("Collection") === isCollection ? -1 : 0) return;
|
|
520
|
+
let elementType = isCollection ? fnDef.returnType.type.slice(11, -1) : fnDef.returnType.type;
|
|
521
|
+
if (NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && !isPrimitive) return;
|
|
522
|
+
if (!NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && isPrimitive) return;
|
|
523
|
+
if (isPrimitive) return elementType;
|
|
524
|
+
|
|
525
|
+
let type;
|
|
526
|
+
for (let i = 0; i < root.schemas.length; i++) {
|
|
527
|
+
let schema = root.schemas[i];
|
|
528
|
+
if (elementType.indexOf(schema.namespace + ".") === 0) {
|
|
529
|
+
for (let j = 0; j < schema[types].length; j++) {
|
|
530
|
+
let it = schema[types][j];
|
|
531
|
+
if (schema.namespace + "." + it.name === elementType) {
|
|
532
|
+
type = it;
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (type) break;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return type;
|
|
541
|
+
}
|
|
542
|
+
export function entityFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
543
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityFunction);
|
|
544
|
+
if (!token) return;
|
|
545
|
+
|
|
546
|
+
if (typeof metadataContext === "object") {
|
|
547
|
+
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, false, false, "entityTypes");
|
|
548
|
+
if (!type) return;
|
|
549
|
+
token.metadata = type;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return token;
|
|
553
|
+
}
|
|
554
|
+
export function entityColFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
555
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityCollectionFunction);
|
|
556
|
+
if (!token) return;
|
|
557
|
+
|
|
558
|
+
if (typeof metadataContext === "object") {
|
|
559
|
+
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, true, false, "entityTypes");
|
|
560
|
+
if (!type) return;
|
|
561
|
+
token.metadata = type;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return token;
|
|
565
|
+
}
|
|
566
|
+
export function complexFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
567
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexFunction);
|
|
568
|
+
if (!token) return;
|
|
569
|
+
|
|
570
|
+
if (typeof metadataContext === "object") {
|
|
571
|
+
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, false, false, "complexTypes");
|
|
572
|
+
if (!type) return;
|
|
573
|
+
token.metadata = type;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return token;
|
|
577
|
+
}
|
|
578
|
+
export function complexColFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
579
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexCollectionFunction);
|
|
580
|
+
if (!token) return;
|
|
581
|
+
|
|
582
|
+
if (typeof metadataContext === "object") {
|
|
583
|
+
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, true, false, "complexTypes");
|
|
584
|
+
if (!type) return;
|
|
585
|
+
token.metadata = type;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return token;
|
|
589
|
+
}
|
|
590
|
+
export function primitiveFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
591
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveFunction);
|
|
592
|
+
if (!token) return;
|
|
593
|
+
|
|
594
|
+
if (typeof metadataContext === "object") {
|
|
595
|
+
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, false, true);
|
|
596
|
+
if (!type) return;
|
|
597
|
+
token.metadata = type;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return token;
|
|
601
|
+
}
|
|
602
|
+
export function primitiveColFunction(value: Utils.SourceArray, index: number, isCollection?: boolean, metadataContext?: any): Lexer.Token {
|
|
603
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveCollectionFunction);
|
|
604
|
+
if (!token) return;
|
|
605
|
+
|
|
606
|
+
if (typeof metadataContext === "object") {
|
|
607
|
+
let type = NameOrIdentifier.getOperationType("function", metadataContext, token, isCollection, true, true);
|
|
608
|
+
if (!type) return;
|
|
609
|
+
token.metadata = type;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
return token;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export function getOperationImportType(operation: string, metadataContext: any, token: Lexer.Token, isCollection?: boolean, isPrimitive?: boolean, types?: string) {
|
|
616
|
+
let fnImport;
|
|
617
|
+
|
|
618
|
+
for (let i = 0; i < metadataContext.dataServices.schemas.length; i++) {
|
|
619
|
+
let schema = metadataContext.dataServices.schemas[i];
|
|
620
|
+
for (let j = 0; j < schema.entityContainer.length; j++) {
|
|
621
|
+
let container = schema.entityContainer[j];
|
|
622
|
+
for (let k = 0; k < container[operation + "Imports"].length; k++) {
|
|
623
|
+
let it = container[operation + "Imports"][k];
|
|
624
|
+
if (it.name === token.raw) {
|
|
625
|
+
fnImport = it;
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (fnImport) break;
|
|
630
|
+
}
|
|
631
|
+
if (fnImport) break;
|
|
632
|
+
}
|
|
633
|
+
if (!fnImport) return;
|
|
634
|
+
|
|
635
|
+
let fn;
|
|
636
|
+
for (let i = 0; i < metadataContext.dataServices.schemas.length; i++) {
|
|
637
|
+
let schema = metadataContext.dataServices.schemas[i];
|
|
638
|
+
if (fnImport[operation].indexOf(schema.namespace + ".") === 0) {
|
|
639
|
+
for (let j = 0; j < schema[operation + "s"].length; j++) {
|
|
640
|
+
let it = schema[operation + "s"][j];
|
|
641
|
+
if (it.name === fnImport.name) {
|
|
642
|
+
fn = it;
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (fn) break;
|
|
648
|
+
}
|
|
649
|
+
if (!fn) return;
|
|
650
|
+
|
|
651
|
+
if (operation === "action") return fn;
|
|
652
|
+
if (fn.returnType.type.indexOf("Collection") === isCollection ? -1 : 0) return;
|
|
653
|
+
let elementType = isCollection ? fn.returnType.type.slice(11, -1) : fn.returnType.type;
|
|
654
|
+
if (NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && !isPrimitive) return;
|
|
655
|
+
if (!NameOrIdentifier.isPrimitiveTypeName(elementType, metadataContext) && isPrimitive) return;
|
|
656
|
+
if (isPrimitive) return elementType;
|
|
657
|
+
|
|
658
|
+
let type;
|
|
659
|
+
for (let i = 0; i < metadataContext.dataServices.schemas.length; i++) {
|
|
660
|
+
let schema = metadataContext.dataServices.schemas[i];
|
|
661
|
+
if (elementType.indexOf(schema.namespace + ".") === 0) {
|
|
662
|
+
for (let j = 0; j < schema[types].length; j++) {
|
|
663
|
+
let it = schema[types][j];
|
|
664
|
+
if (schema.namespace + "." + it.name === elementType) {
|
|
665
|
+
type = it;
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (type) break;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return type;
|
|
674
|
+
}
|
|
675
|
+
export function entityFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
676
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityFunctionImport);
|
|
677
|
+
if (!token) return;
|
|
678
|
+
|
|
679
|
+
if (typeof metadataContext === "object") {
|
|
680
|
+
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, false, false, "entityTypes");
|
|
681
|
+
if (!type) return;
|
|
682
|
+
token.metadata = type;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return token;
|
|
686
|
+
}
|
|
687
|
+
export function entityColFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
688
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.EntityCollectionFunctionImport);
|
|
689
|
+
if (!token) return;
|
|
690
|
+
|
|
691
|
+
if (typeof metadataContext === "object") {
|
|
692
|
+
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, true, false, "entityTypes");
|
|
693
|
+
if (!type) return;
|
|
694
|
+
token.metadata = type;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
return token;
|
|
698
|
+
}
|
|
699
|
+
export function complexFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
700
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexFunctionImport);
|
|
701
|
+
if (!token) return;
|
|
702
|
+
|
|
703
|
+
if (typeof metadataContext === "object") {
|
|
704
|
+
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, false, false, "complexTypes");
|
|
705
|
+
if (!type) return;
|
|
706
|
+
token.metadata = type;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
return token;
|
|
710
|
+
}
|
|
711
|
+
export function complexColFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
712
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.ComplexCollectionFunctionImport);
|
|
713
|
+
if (!token) return;
|
|
714
|
+
|
|
715
|
+
if (typeof metadataContext === "object") {
|
|
716
|
+
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, true, false, "complexTypes");
|
|
717
|
+
if (!type) return;
|
|
718
|
+
token.metadata = type;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return token;
|
|
722
|
+
}
|
|
723
|
+
export function primitiveFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
724
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveFunctionImport);
|
|
725
|
+
if (!token) return;
|
|
726
|
+
|
|
727
|
+
if (typeof metadataContext === "object") {
|
|
728
|
+
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, false, true);
|
|
729
|
+
if (!type) return;
|
|
730
|
+
token.metadata = type;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
return token;
|
|
734
|
+
}
|
|
735
|
+
export function primitiveColFunctionImport(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
736
|
+
let token = NameOrIdentifier.odataIdentifier(value, index, Lexer.TokenType.PrimitiveCollectionFunctionImport);
|
|
737
|
+
if (!token) return;
|
|
738
|
+
|
|
739
|
+
if (typeof metadataContext === "object") {
|
|
740
|
+
let type = NameOrIdentifier.getOperationImportType("function", metadataContext, token, true, true);
|
|
741
|
+
if (!type) return;
|
|
742
|
+
token.metadata = type;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
return token;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
749
|
export default NameOrIdentifier;
|