angular-odata 0.142.0 → 0.144.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/fesm2022/angular-odata.mjs +65 -52
  3. package/fesm2022/angular-odata.mjs.map +1 -1
  4. package/package.json +1 -1
  5. package/schematics/apigen/angular/api-config.d.ts +2 -1
  6. package/schematics/apigen/angular/api-config.js +1 -1
  7. package/schematics/apigen/angular/api-config.js.map +1 -1
  8. package/schematics/apigen/angular/base.d.ts +4 -5
  9. package/schematics/apigen/angular/base.js +12 -8
  10. package/schematics/apigen/angular/base.js.map +1 -1
  11. package/schematics/apigen/angular/collection.d.ts +2 -1
  12. package/schematics/apigen/angular/collection.js +1 -1
  13. package/schematics/apigen/angular/collection.js.map +1 -1
  14. package/schematics/apigen/angular/entity.d.ts +6 -2
  15. package/schematics/apigen/angular/entity.js +15 -5
  16. package/schematics/apigen/angular/entity.js.map +1 -1
  17. package/schematics/apigen/angular/enum.d.ts +2 -1
  18. package/schematics/apigen/angular/enum.js +1 -1
  19. package/schematics/apigen/angular/enum.js.map +1 -1
  20. package/schematics/apigen/angular/import.d.ts +3 -2
  21. package/schematics/apigen/angular/import.js +4 -3
  22. package/schematics/apigen/angular/import.js.map +1 -1
  23. package/schematics/apigen/angular/model.d.ts +12 -8
  24. package/schematics/apigen/angular/model.js +47 -38
  25. package/schematics/apigen/angular/model.js.map +1 -1
  26. package/schematics/apigen/angular/module.d.ts +2 -1
  27. package/schematics/apigen/angular/module.js +1 -1
  28. package/schematics/apigen/angular/module.js.map +1 -1
  29. package/schematics/apigen/angular/service.d.ts +2 -1
  30. package/schematics/apigen/angular/service.js +1 -1
  31. package/schematics/apigen/angular/service.js.map +1 -1
  32. package/schematics/apigen/files/api-config/__fileName__.ts +4 -2
  33. package/schematics/apigen/files/collection/__fileName__.ts +4 -0
  34. package/schematics/apigen/files/entity/__fileName__.ts +6 -2
  35. package/schematics/apigen/files/entitycontainer-service/__fileName__.ts +4 -0
  36. package/schematics/apigen/files/entityset-service/__fileName__.ts +4 -0
  37. package/schematics/apigen/files/enum/__fileName__.ts +4 -0
  38. package/schematics/apigen/files/index/__fileName__.ts +2 -0
  39. package/schematics/apigen/files/model/__fileName__.ts +8 -4
  40. package/schematics/apigen/files/module/__fileName__.ts +2 -0
  41. package/schematics/apigen/files/singleton-service/__fileName__.ts +4 -0
  42. package/schematics/apigen/index.js +53 -8
  43. package/schematics/apigen/index.js.map +1 -1
  44. package/schematics/random.d.ts +4 -1
  45. package/schematics/random.js +2 -2
  46. package/schematics/random.js.map +1 -1
  47. package/types/angular-odata.d.ts +37 -41
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <p align="center">
9
9
  <a href="CONTRIBUTING.md">Contributing</a>
10
10
  ·
11
- <a href="./docs/README.md">Documentation</a>
11
+ <a href="./docs/api/index.html">Documentation</a>
12
12
  ·
13
13
  <a href="https://github.com/diegomvh/AngularODataEntity">Demo</a>
14
14
  <br>
@@ -107,16 +107,16 @@ var EdmType;
107
107
  //Edm.GeometryCollection Collection of arbitrary Geometry values
108
108
  EdmType["GeometryCollection"] = "Edm.GeometryCollection";
109
109
  })(EdmType || (EdmType = {}));
110
- var JsonType;
111
- (function (JsonType) {
112
- JsonType["string"] = "string";
113
- JsonType["number"] = "number";
114
- JsonType["integer"] = "integer";
115
- JsonType["object"] = "object";
116
- JsonType["array"] = "array";
117
- JsonType["boolean"] = "boolean";
118
- JsonType["null"] = "null";
119
- })(JsonType || (JsonType = {}));
110
+ var JsonSchemaType;
111
+ (function (JsonSchemaType) {
112
+ JsonSchemaType["string"] = "string";
113
+ JsonSchemaType["number"] = "number";
114
+ JsonSchemaType["integer"] = "integer";
115
+ JsonSchemaType["object"] = "object";
116
+ JsonSchemaType["array"] = "array";
117
+ JsonSchemaType["boolean"] = "boolean";
118
+ JsonSchemaType["null"] = "null";
119
+ })(JsonSchemaType || (JsonSchemaType = {}));
120
120
  const NONE_PARSER = {
121
121
  deserialize: (value) => value,
122
122
  serialize: (value) => value,
@@ -1168,7 +1168,7 @@ const Durations = {
1168
1168
  v.months ? v.months + 'M' : '',
1169
1169
  v.weeks ? v.weeks + 'W' : '',
1170
1170
  v.days ? v.days + 'D' : '',
1171
- 'T',
1171
+ (v.hours || v.minutes || v.seconds) ? 'T' : '',
1172
1172
  v.hours ? v.hours + 'H' : '',
1173
1173
  v.minutes ? v.minutes + 'M' : '',
1174
1174
  v.seconds ? v.seconds + 'S' : '',
@@ -2131,19 +2131,23 @@ class ODataEnumTypeParser extends ODataAnnotatable {
2131
2131
  return parserOptions?.stringAsEnum ? raw(`'${serialized}'`) : raw(serialized);
2132
2132
  }
2133
2133
  // Json Schema
2134
- toJsonSchema() {
2135
- return this.flags
2134
+ toJsonSchema(options, parent) {
2135
+ let schema = (this.flags
2136
2136
  ? {
2137
2137
  title: this.name,
2138
- type: JsonType.array,
2138
+ type: JsonSchemaType.array,
2139
2139
  items: {
2140
- type: JsonType.integer,
2140
+ type: JsonSchemaType.integer,
2141
2141
  },
2142
2142
  }
2143
2143
  : {
2144
- type: JsonType.integer,
2144
+ type: JsonSchemaType.integer,
2145
2145
  enum: this._fields.map((f) => f.value),
2146
- };
2146
+ });
2147
+ if (options?.map !== undefined) {
2148
+ schema = options.map(schema, parent);
2149
+ }
2150
+ return schema;
2147
2151
  }
2148
2152
  validate(value, { method, navigation = false, } = {}) {
2149
2153
  if (this.flags) {
@@ -2305,39 +2309,39 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
2305
2309
  }
2306
2310
  //#region Json Schema
2307
2311
  // https://json-schema.org/
2308
- toJsonSchema(options = {}) {
2312
+ toJsonSchema(options, parent) {
2309
2313
  let schema = this.parser instanceof ODataStructuredTypeFieldParser ||
2310
2314
  this.parser instanceof ODataStructuredTypeParser ||
2311
2315
  this.parser instanceof ODataEnumTypeParser
2312
- ? this.parser.toJsonSchema(options)
2313
- : { title: this.name, type: JsonType.object };
2316
+ ? this.parser.toJsonSchema(options, parent)
2317
+ : { title: this.name };
2314
2318
  switch (this.type) {
2315
2319
  case EdmType.String:
2316
- schema.type = JsonType.string;
2320
+ schema.type = JsonSchemaType.string;
2317
2321
  break;
2318
2322
  case EdmType.Guid:
2319
- schema.type = JsonType.string;
2323
+ schema.type = JsonSchemaType.string;
2320
2324
  schema.pattern =
2321
2325
  '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$';
2322
2326
  break;
2323
2327
  case EdmType.Binary:
2324
- schema.type = JsonType.string;
2328
+ schema.type = JsonSchemaType.string;
2325
2329
  schema.contentEncoding = 'base64';
2326
2330
  break;
2327
2331
  case EdmType.Date:
2328
- schema.type = JsonType.string;
2332
+ schema.type = JsonSchemaType.string;
2329
2333
  schema.format = 'date';
2330
2334
  break;
2331
2335
  case EdmType.TimeOfDay:
2332
- schema.type = JsonType.string;
2336
+ schema.type = JsonSchemaType.string;
2333
2337
  schema.format = 'time';
2334
2338
  break;
2335
2339
  case EdmType.DateTimeOffset:
2336
- schema.type = JsonType.string;
2340
+ schema.type = JsonSchemaType.string;
2337
2341
  schema.format = 'date-time';
2338
2342
  break;
2339
2343
  case EdmType.Duration:
2340
- schema.type = JsonType.string;
2344
+ schema.type = JsonSchemaType.string;
2341
2345
  schema.format = 'duration';
2342
2346
  break;
2343
2347
  case EdmType.Byte:
@@ -2346,15 +2350,15 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
2346
2350
  case EdmType.Int32:
2347
2351
  case EdmType.Int64:
2348
2352
  //TODO: Range
2349
- schema.type = JsonType.integer;
2353
+ schema.type = JsonSchemaType.integer;
2350
2354
  break;
2351
2355
  case EdmType.Single:
2352
2356
  case EdmType.Double:
2353
2357
  case EdmType.Decimal:
2354
- schema.type = JsonType.number;
2358
+ schema.type = JsonSchemaType.number;
2355
2359
  break;
2356
2360
  case EdmType.Boolean:
2357
- schema.type = JsonType.boolean;
2361
+ schema.type = JsonSchemaType.boolean;
2358
2362
  break;
2359
2363
  }
2360
2364
  if (this.maxLength)
@@ -2362,13 +2366,16 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
2362
2366
  if (this.default)
2363
2367
  schema.default = this.default;
2364
2368
  if (this.nullable)
2365
- schema.type = [schema.type, JsonType.null];
2369
+ schema.type = [schema.type, JsonSchemaType.null];
2366
2370
  if (this.collection)
2367
2371
  schema = {
2368
- type: JsonType.array,
2372
+ type: JsonSchemaType.array,
2369
2373
  items: schema,
2370
2374
  additionalItems: false,
2371
2375
  };
2376
+ if (options?.map !== undefined) {
2377
+ schema = options.map(schema, parent);
2378
+ }
2372
2379
  return schema;
2373
2380
  }
2374
2381
  //#endregion
@@ -2627,40 +2634,43 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
2627
2634
  };
2628
2635
  }
2629
2636
  // Json Schema
2630
- toJsonSchema(options = {}) {
2637
+ toJsonSchema(options, parent) {
2631
2638
  let schema = {
2632
2639
  $schema: 'http://json-schema.org/draft-07/schema#',
2633
2640
  $id: `${this.namespace}.${this.name}`,
2634
2641
  title: this.titleize(DESCRIPTION),
2635
2642
  description: this.annotatedValue(LONG_DESCRIPTION),
2636
- type: JsonType.object,
2643
+ type: JsonSchemaType.object,
2637
2644
  properties: {},
2638
2645
  required: [],
2639
2646
  };
2640
2647
  const fields = this.fields({
2641
2648
  include_navigation: true,
2642
2649
  include_parents: true,
2643
- }).filter((f) => (!f.navigation || (options.expand && f.name in options.expand)) &&
2644
- (!options.select || options.select.indexOf(f.name) !== -1));
2645
- schema.properties = Object.assign({}, schema.properties, fields
2646
- .map((f) => {
2647
- let expand = options.expand && f.name in options.expand
2648
- ? options.expand[f.name]
2649
- : undefined;
2650
- let schema = f.toJsonSchema(expand);
2651
- if (options.custom && f.name in options.custom)
2652
- schema = options.custom[f.name](schema, f);
2653
- return { [f.name]: schema };
2654
- })
2655
- .reduce((acc, v) => Object.assign(acc, v), {}));
2650
+ }).filter((f) => (!f.navigation || (options?.expand && f.name in options?.expand)) &&
2651
+ (!options?.select || (options?.select).indexOf(f.name) !== -1));
2656
2652
  schema.required = [
2657
- ...schema.required,
2653
+ ...(schema.required ?? []),
2658
2654
  ...fields
2659
- .filter((f) => options.required && f.name in options.required
2660
- ? options.required[f.name]
2655
+ .filter((f) => options?.required && f.name in options?.required
2656
+ ? options?.required[f.name]
2661
2657
  : !f.nullable)
2662
2658
  .map((f) => f.name),
2663
2659
  ];
2660
+ schema.properties = Object.assign({}, schema.properties, fields
2661
+ .map((f) => {
2662
+ let expand = options?.expand && f.name in options?.expand
2663
+ ? (options?.expand)[f.name]
2664
+ : undefined;
2665
+ let child = f.toJsonSchema({ ...expand, map: options?.map }, schema);
2666
+ if (options?.custom && f.name in options?.custom)
2667
+ child = (options?.custom[f.name])(child, f);
2668
+ return { [f.name]: child };
2669
+ })
2670
+ .reduce((acc, v) => Object.assign(acc, v), {}));
2671
+ if (options?.map !== undefined) {
2672
+ schema = options.map(schema, parent);
2673
+ }
2664
2674
  return schema;
2665
2675
  }
2666
2676
  validate(attrs, { method, navigation = false, } = {}) {
@@ -3157,7 +3167,7 @@ class ODataStructuredType extends ODataParserSchemaElement {
3157
3167
  * @param options Options for json schema
3158
3168
  * @returns Json Schema
3159
3169
  */
3160
- toJsonSchema(options = {}) {
3170
+ toJsonSchema(options) {
3161
3171
  return this.parser.toJsonSchema(options);
3162
3172
  }
3163
3173
  /**
@@ -12000,6 +12010,9 @@ class ODataModelOptions {
12000
12010
  isTypeOf(type) {
12001
12011
  return this.structuredType.type() === type;
12002
12012
  }
12013
+ toJsonSchema(options) {
12014
+ return this.structuredType.toJsonSchema(options);
12015
+ }
12003
12016
  isModelFor(entity) {
12004
12017
  // Resolve By Type
12005
12018
  const type = this.api.options.helper.type(entity);
@@ -14148,5 +14161,5 @@ class ODataInStorageCache extends ODataBaseCache {
14148
14161
  * Generated bundle index. Do not edit.
14149
14162
  */
14150
14163
 
14151
- export { Aggregate, ApplyExpression, ArithmeticFunctions, ArithmeticOperators, BUBBLES, CollectionFunctions, ComputeExpression, ConditionalFunctions, DateAndTimeFunctions, Dates, Durations, EDM_PARSERS, EdmType, Enums, ExpandExpression, ExpandField, Expression, FieldFactory, FilterExpression, Function, GeoFunctions, GroupBy, GroupByTransformations, Grouping, GroupingOperators, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, JsonType, Lambda, LambdaOperators, LogicalOperators, Model, ModelField, NONE_PARSER, ODATA_CONFIG, OData, ODataActionResource, ODataAnnotations, ODataApi, ODataBaseCache, ODataBaseService, ODataBatchRequest, ODataBatchResource, ODataCallable, ODataCallableParser, ODataClient, ODataCollection, ODataConfigAsyncLoader, ODataConfigLoader, ODataConfigSyncLoader, ODataCountResource, ODataEntitiesAnnotations, ODataEntityAnnotations, ODataEntityContainer, ODataEntityResource, ODataEntitySet, ODataEntitySetResource, ODataEntitySetService, ODataEntityTypeKey, ODataEnumType, ODataEnumTypeFieldParser, ODataEnumTypeParser, ODataFunctionResource, ODataFunctions, ODataInMemoryCache, ODataInStorageCache, ODataMediaResource, ODataMetadata, ODataMetadataLoader, ODataMetadataParser, ODataMetadataResource, ODataModel, ODataModelAttribute, ODataModelEvent, ODataModelEventEmitter, ODataModelEventType, ODataModelField, ODataModelOptions, ODataModelState, ODataModule, ODataNavigationPropertyResource, ODataOperators, ODataParameterParser, ODataPathSegments, ODataPathSegmentsHandler, ODataPropertyAnnotations, ODataPropertyResource, ODataQueryOptionHandler, ODataQueryOptions, ODataQueryOptionsHandler, ODataReferenceResource, ODataReferential, ODataRequest, ODataResource, ODataResponse, ODataSchema, ODataServiceFactory, ODataSettings, ODataSingleton, ODataSingletonResource, ODataSingletonService, ODataStructuredType, ODataStructuredTypeFieldParser, ODataStructuredTypeParser, ODataSyntax, ODataTransformations, ODataValueResource, Objects, Operator, OrderByExpression, OrderByField, PathSegment, QueryCustomTypes, QueryOption, RenderableFactory, SearchExpression, SearchTerm, SegmentHandler, SelectExpression, StandardAggregateMethods, StringAndCollectionFunctions, StringFunctions, Strings, Transformations, Type, TypeFunctions, Types, Urls, alias, binary, buildPathAndQuery, createSyncLoader, duration, encode, functions, isQueryCustomType, isRawType, normalizeValue, operators, pathAndParamsFromQueryOptions, pathAndParamsFromSegments, provideODataClient, raw, render, resolve, syntax, transformations };
14164
+ export { Aggregate, ApplyExpression, ArithmeticFunctions, ArithmeticOperators, BUBBLES, CollectionFunctions, ComputeExpression, ConditionalFunctions, DateAndTimeFunctions, Dates, Durations, EDM_PARSERS, EdmType, Enums, ExpandExpression, ExpandField, Expression, FieldFactory, FilterExpression, Function, GeoFunctions, GroupBy, GroupByTransformations, Grouping, GroupingOperators, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, JsonSchemaType, Lambda, LambdaOperators, LogicalOperators, Model, ModelField, NONE_PARSER, ODATA_CONFIG, OData, ODataActionResource, ODataAnnotations, ODataApi, ODataBaseCache, ODataBaseService, ODataBatchRequest, ODataBatchResource, ODataCallable, ODataCallableParser, ODataClient, ODataCollection, ODataConfigAsyncLoader, ODataConfigLoader, ODataConfigSyncLoader, ODataCountResource, ODataEntitiesAnnotations, ODataEntityAnnotations, ODataEntityContainer, ODataEntityResource, ODataEntitySet, ODataEntitySetResource, ODataEntitySetService, ODataEntityTypeKey, ODataEnumType, ODataEnumTypeFieldParser, ODataEnumTypeParser, ODataFunctionResource, ODataFunctions, ODataInMemoryCache, ODataInStorageCache, ODataMediaResource, ODataMetadata, ODataMetadataLoader, ODataMetadataParser, ODataMetadataResource, ODataModel, ODataModelAttribute, ODataModelEvent, ODataModelEventEmitter, ODataModelEventType, ODataModelField, ODataModelOptions, ODataModelState, ODataModule, ODataNavigationPropertyResource, ODataOperators, ODataParameterParser, ODataPathSegments, ODataPathSegmentsHandler, ODataPropertyAnnotations, ODataPropertyResource, ODataQueryOptionHandler, ODataQueryOptions, ODataQueryOptionsHandler, ODataReferenceResource, ODataReferential, ODataRequest, ODataResource, ODataResponse, ODataSchema, ODataServiceFactory, ODataSettings, ODataSingleton, ODataSingletonResource, ODataSingletonService, ODataStructuredType, ODataStructuredTypeFieldParser, ODataStructuredTypeParser, ODataSyntax, ODataTransformations, ODataValueResource, Objects, Operator, OrderByExpression, OrderByField, PathSegment, QueryCustomTypes, QueryOption, RenderableFactory, SearchExpression, SearchTerm, SegmentHandler, SelectExpression, StandardAggregateMethods, StringAndCollectionFunctions, StringFunctions, Strings, Transformations, Type, TypeFunctions, Types, Urls, alias, binary, buildPathAndQuery, createSyncLoader, duration, encode, functions, isQueryCustomType, isRawType, normalizeValue, operators, pathAndParamsFromQueryOptions, pathAndParamsFromSegments, provideODataClient, raw, render, resolve, syntax, transformations };
14152
14165
  //# sourceMappingURL=angular-odata.mjs.map