@steedos/odata-v4-parser 2.2.53-beta.3

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