@rxap/open-api 12.4.0 → 13.0.0-next.10

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 (113) hide show
  1. package/data-source/package.json +5 -5
  2. package/data-source/table/package.json +5 -5
  3. package/esm2020/data-source/lib/error.mjs +8 -0
  4. package/esm2020/data-source/lib/open-api-data-source.loader.mjs +36 -0
  5. package/esm2020/data-source/lib/open-api.data-source.mjs +140 -0
  6. package/esm2020/data-source/public_api.mjs +6 -0
  7. package/esm2020/data-source/rxap-open-api-data-source.mjs +5 -0
  8. package/esm2020/data-source/table/lib/error.mjs +8 -0
  9. package/esm2020/data-source/table/lib/open-api-table.data-source.mjs +127 -0
  10. package/esm2020/data-source/table/lib/to-open-api-table-data-source.pipe.mjs +29 -0
  11. package/esm2020/data-source/table/lib/tokens.mjs +3 -0
  12. package/esm2020/data-source/table/public_api.mjs +5 -0
  13. package/esm2020/data-source/table/rxap-open-api-data-source-table.mjs +5 -0
  14. package/esm2020/index.mjs +7 -0
  15. package/esm2020/lib/error.mjs +7 -0
  16. package/esm2020/lib/open-api-config.service.mjs +160 -0
  17. package/esm2020/lib/open-api.mjs +2 -0
  18. package/esm2020/lib/schema-validation.mixin.mjs +256 -0
  19. package/esm2020/lib/tokens.mjs +8 -0
  20. package/esm2020/lib/utilities.mjs +16 -0
  21. package/esm2020/remote-method/lib/error.mjs +8 -0
  22. package/esm2020/remote-method/lib/open-api-remote-method.loader.mjs +37 -0
  23. package/esm2020/remote-method/lib/open-api.remote-method.mjs +145 -0
  24. package/esm2020/remote-method/public_api.mjs +4 -0
  25. package/esm2020/remote-method/rxap-open-api-remote-method.mjs +5 -0
  26. package/esm2020/rxap-open-api.mjs +5 -0
  27. package/fesm2015/rxap-open-api-data-source-table.mjs +172 -0
  28. package/fesm2015/rxap-open-api-data-source-table.mjs.map +1 -0
  29. package/{esm2015/data-source/lib/open-api.data-source.js → fesm2015/rxap-open-api-data-source.mjs} +96 -49
  30. package/fesm2015/rxap-open-api-data-source.mjs.map +1 -0
  31. package/fesm2015/rxap-open-api-remote-method.mjs +201 -0
  32. package/fesm2015/rxap-open-api-remote-method.mjs.map +1 -0
  33. package/fesm2015/{rxap-open-api.js → rxap-open-api.mjs} +55 -20
  34. package/fesm2015/rxap-open-api.mjs.map +1 -0
  35. package/{fesm2015/rxap-open-api-data-source-table.js → fesm2020/rxap-open-api-data-source-table.mjs} +18 -20
  36. package/fesm2020/rxap-open-api-data-source-table.mjs.map +1 -0
  37. package/{fesm2015/rxap-open-api-data-source.js → fesm2020/rxap-open-api-data-source.mjs} +17 -18
  38. package/fesm2020/rxap-open-api-data-source.mjs.map +1 -0
  39. package/{fesm2015/rxap-open-api-remote-method.js → fesm2020/rxap-open-api-remote-method.mjs} +50 -46
  40. package/fesm2020/rxap-open-api-remote-method.mjs.map +1 -0
  41. package/{esm2015/lib/schema-validation.mixin.js → fesm2020/rxap-open-api.mjs} +197 -8
  42. package/fesm2020/rxap-open-api.mjs.map +1 -0
  43. package/lib/open-api-config.service.d.ts +6 -4
  44. package/package.json +60 -22
  45. package/remote-method/lib/open-api.remote-method.d.ts +16 -1
  46. package/remote-method/package.json +5 -5
  47. package/src/schematics/open-api/coerce-open-api-project.js +4 -3
  48. package/src/schematics/open-api/coerce-open-api-project.js.map +1 -1
  49. package/src/schematics/open-api/create-directive.js +6 -7
  50. package/src/schematics/open-api/create-directive.js.map +1 -1
  51. package/src/schematics/open-api/generate-data-source.js +1 -1
  52. package/src/schematics/open-api/generate-remote-method.js +5 -2
  53. package/src/schematics/open-api/generate-remote-method.js.map +1 -1
  54. package/src/schematics/open-api/index.js +1 -1
  55. package/src/schematics/open-api/schema.json +6 -0
  56. package/bundles/rxap-open-api-data-source-table.umd.js +0 -534
  57. package/bundles/rxap-open-api-data-source-table.umd.js.map +0 -1
  58. package/bundles/rxap-open-api-data-source.umd.js +0 -548
  59. package/bundles/rxap-open-api-data-source.umd.js.map +0 -1
  60. package/bundles/rxap-open-api-remote-method.umd.js +0 -557
  61. package/bundles/rxap-open-api-remote-method.umd.js.map +0 -1
  62. package/bundles/rxap-open-api.umd.js +0 -868
  63. package/bundles/rxap-open-api.umd.js.map +0 -1
  64. package/esm2015/data-source/lib/error.js +0 -8
  65. package/esm2015/data-source/lib/error.js.map +0 -1
  66. package/esm2015/data-source/lib/open-api-data-source.loader.js +0 -36
  67. package/esm2015/data-source/lib/open-api-data-source.loader.js.map +0 -1
  68. package/esm2015/data-source/lib/open-api.data-source.js.map +0 -1
  69. package/esm2015/data-source/public_api.js +0 -6
  70. package/esm2015/data-source/public_api.js.map +0 -1
  71. package/esm2015/data-source/rxap-open-api-data-source.js +0 -5
  72. package/esm2015/data-source/rxap-open-api-data-source.js.map +0 -1
  73. package/esm2015/data-source/table/lib/error.js +0 -8
  74. package/esm2015/data-source/table/lib/error.js.map +0 -1
  75. package/esm2015/data-source/table/lib/open-api-table.data-source.js +0 -129
  76. package/esm2015/data-source/table/lib/open-api-table.data-source.js.map +0 -1
  77. package/esm2015/data-source/table/lib/to-open-api-table-data-source.pipe.js +0 -29
  78. package/esm2015/data-source/table/lib/to-open-api-table-data-source.pipe.js.map +0 -1
  79. package/esm2015/data-source/table/lib/tokens.js +0 -3
  80. package/esm2015/data-source/table/lib/tokens.js.map +0 -1
  81. package/esm2015/data-source/table/public_api.js +0 -5
  82. package/esm2015/data-source/table/public_api.js.map +0 -1
  83. package/esm2015/data-source/table/rxap-open-api-data-source-table.js +0 -5
  84. package/esm2015/data-source/table/rxap-open-api-data-source-table.js.map +0 -1
  85. package/esm2015/index.js +0 -7
  86. package/esm2015/index.js.map +0 -1
  87. package/esm2015/lib/error.js +0 -7
  88. package/esm2015/lib/error.js.map +0 -1
  89. package/esm2015/lib/open-api-config.service.js +0 -127
  90. package/esm2015/lib/open-api-config.service.js.map +0 -1
  91. package/esm2015/lib/open-api.js +0 -2
  92. package/esm2015/lib/open-api.js.map +0 -1
  93. package/esm2015/lib/schema-validation.mixin.js.map +0 -1
  94. package/esm2015/lib/tokens.js +0 -8
  95. package/esm2015/lib/tokens.js.map +0 -1
  96. package/esm2015/lib/utilities.js +0 -16
  97. package/esm2015/lib/utilities.js.map +0 -1
  98. package/esm2015/remote-method/lib/error.js +0 -8
  99. package/esm2015/remote-method/lib/error.js.map +0 -1
  100. package/esm2015/remote-method/lib/open-api-remote-method.loader.js +0 -37
  101. package/esm2015/remote-method/lib/open-api-remote-method.loader.js.map +0 -1
  102. package/esm2015/remote-method/lib/open-api.remote-method.js +0 -141
  103. package/esm2015/remote-method/lib/open-api.remote-method.js.map +0 -1
  104. package/esm2015/remote-method/public_api.js +0 -4
  105. package/esm2015/remote-method/public_api.js.map +0 -1
  106. package/esm2015/remote-method/rxap-open-api-remote-method.js +0 -5
  107. package/esm2015/remote-method/rxap-open-api-remote-method.js.map +0 -1
  108. package/esm2015/rxap-open-api.js +0 -5
  109. package/esm2015/rxap-open-api.js.map +0 -1
  110. package/fesm2015/rxap-open-api-data-source-table.js.map +0 -1
  111. package/fesm2015/rxap-open-api-data-source.js.map +0 -1
  112. package/fesm2015/rxap-open-api-remote-method.js.map +0 -1
  113. package/fesm2015/rxap-open-api.js.map +0 -1
@@ -52,10 +52,9 @@ let OpenApiDataSource = OpenApiDataSource_1 = class OpenApiDataSource extends Ba
52
52
  return this.metadata.operation;
53
53
  }
54
54
  derive(id, metadata = this.metadata, isolated = false) {
55
- return new OpenApiDataSource_1(this.http, this.openApiConfigService, Object.assign(Object.assign({}, deepMerge(this.metadata, metadata)), { id }), isolated ? null : this.refresh$);
55
+ return new OpenApiDataSource_1(this.http, this.openApiConfigService, { ...deepMerge(this.metadata, metadata), id }, isolated ? null : this.refresh$);
56
56
  }
57
57
  connect(viewer) {
58
- var _a;
59
58
  if (viewer.parameters) {
60
59
  if (!this.disableValidation) {
61
60
  this.validateParameters(this.operation, viewer.parameters, this.strict);
@@ -71,20 +70,21 @@ let OpenApiDataSource = OpenApiDataSource_1 = class OpenApiDataSource extends Ba
71
70
  }
72
71
  }
73
72
  }
74
- return super.connect(Object.assign(Object.assign(Object.assign({}, viewer), this.buildHttpOptions(this.operation, viewer.parameters)), {
73
+ return super.connect({
74
+ ...viewer,
75
+ ...this.buildHttpOptions(this.operation, viewer.parameters),
75
76
  // if the view change is an empty observable. Then dont apply the pipe logic
76
77
  // else the http request is never triggered
77
- viewChange: viewer.viewChange === EMPTY ? viewer.viewChange : (_a = viewer.viewChange) === null || _a === void 0 ? void 0 : _a.pipe(tap(parameters => {
78
+ viewChange: viewer.viewChange === EMPTY ? viewer.viewChange : viewer.viewChange?.pipe(tap(parameters => {
78
79
  if (!this.disableValidation) {
79
80
  this.validateParameters(this.operation, parameters, this.strict);
80
81
  }
81
- }), map(parameters => this.buildHttpOptions(this.operation, parameters))) }));
82
+ }), map(parameters => this.buildHttpOptions(this.operation, parameters)))
83
+ });
82
84
  }
83
85
  buildRequest(options) {
84
- var _a;
85
- return this.http.request(this.buildHttpRequest(options)).pipe(retry((_a = this.metadata.retry) !== null && _a !== void 0 ? _a : 0), catchError((response) => {
86
- var _a;
87
- (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.forEach(interceptor => interceptor
86
+ return this.http.request(this.buildHttpRequest(options)).pipe(retry(this.metadata.retry ?? 0), catchError((response) => {
87
+ this.interceptors?.forEach(interceptor => interceptor
88
88
  .next({ response, options }));
89
89
  return throwError(response);
90
90
  }), filter((event) => event.type === HttpEventType.Response), tap((response) => {
@@ -92,20 +92,19 @@ let OpenApiDataSource = OpenApiDataSource_1 = class OpenApiDataSource extends Ba
92
92
  this.validateResponse(this.operation, response, this.strict);
93
93
  }
94
94
  }), tap((response) => {
95
- var _a;
96
- (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.forEach(interceptor => interceptor
95
+ this.interceptors?.forEach(interceptor => interceptor
97
96
  .next({ response, options }));
98
97
  }), map((event) => event.body), isDefined(), take(1), timeout(this.timeout));
99
98
  }
100
99
  };
101
- OpenApiDataSource.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiDataSource, deps: [{ token: HttpClient }, { token: OpenApiConfigService }, { token: DEFAULT_OPEN_API_DATA_SOURCE_META_DATA, optional: true }, { token: RXAP_DATA_SOURCE_REFRESH, optional: true }, { token: RXAP_OPEN_API_STRICT_VALIDATOR, optional: true }, { token: DISABLE_SCHEMA_VALIDATION, optional: true }, { token: DISABLE_VALIDATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
102
- OpenApiDataSource.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiDataSource });
100
+ OpenApiDataSource.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiDataSource, deps: [{ token: HttpClient }, { token: OpenApiConfigService }, { token: DEFAULT_OPEN_API_DATA_SOURCE_META_DATA, optional: true }, { token: RXAP_DATA_SOURCE_REFRESH, optional: true }, { token: RXAP_OPEN_API_STRICT_VALIDATOR, optional: true }, { token: DISABLE_SCHEMA_VALIDATION, optional: true }, { token: DISABLE_VALIDATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
101
+ OpenApiDataSource.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiDataSource });
103
102
  OpenApiDataSource = OpenApiDataSource_1 = __decorate([
104
103
  Mixin(SchemaValidationMixin),
105
104
  __metadata("design:paramtypes", [HttpClient,
106
105
  OpenApiConfigService, Object, Object, Object, Object, Object])
107
106
  ], OpenApiDataSource);
108
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiDataSource, decorators: [{
107
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiDataSource, decorators: [{
109
108
  type: Injectable
110
109
  }], ctorParameters: function () { return [{ type: i1.HttpClient, decorators: [{
111
110
  type: Inject,
@@ -156,9 +155,9 @@ class OpenApiDataSourceLoader {
156
155
  return null;
157
156
  }
158
157
  }
159
- OpenApiDataSourceLoader.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiDataSourceLoader, deps: [{ token: OpenApiConfigService }, { token: HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
160
- OpenApiDataSourceLoader.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiDataSourceLoader, providedIn: 'root' });
161
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiDataSourceLoader, decorators: [{
158
+ OpenApiDataSourceLoader.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiDataSourceLoader, deps: [{ token: OpenApiConfigService }, { token: HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
159
+ OpenApiDataSourceLoader.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiDataSourceLoader, providedIn: 'root' });
160
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiDataSourceLoader, decorators: [{
162
161
  type: Injectable,
163
162
  args: [{ providedIn: 'root' }]
164
163
  }], ctorParameters: function () { return [{ type: i2.OpenApiConfigService, decorators: [{
@@ -181,4 +180,4 @@ class RxapOpenApiDataSourceError extends RxapOpenApiError {
181
180
  */
182
181
 
183
182
  export { OpenApiDataSource, OpenApiDataSourceLoader, RxapOpenApiDataSource, RxapOpenApiDataSourceError };
184
- //# sourceMappingURL=rxap-open-api-data-source.js.map
183
+ //# sourceMappingURL=rxap-open-api-data-source.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rxap-open-api-data-source.mjs","sources":["../../../../libs/open-api/data-source/src/lib/open-api.data-source.ts","../../../../libs/open-api/data-source/src/lib/open-api-data-source.loader.ts","../../../../libs/open-api/data-source/src/lib/error.ts","../../../../libs/open-api/data-source/src/rxap-open-api-data-source.ts"],"sourcesContent":["import {\n Injectable,\n Optional,\n Inject\n} from '@angular/core';\nimport {\n OperationObjectWithMetadata,\n OpenApiConfigService,\n SchemaValidationMixin,\n RXAP_OPEN_API_STRICT_VALIDATOR,\n DEFAULT_OPEN_API_DATA_SOURCE_META_DATA,\n DISABLE_SCHEMA_VALIDATION,\n DISABLE_VALIDATION\n} from '@rxap/open-api';\nimport {\n HttpClient,\n HttpResponse,\n HttpErrorResponse,\n HttpEventType\n} from '@angular/common/http';\nimport {\n KeyValue,\n joinPath,\n deepMerge\n} from '@rxap/utilities';\nimport {\n HttpDataSourceMetadata,\n HttpDataSourceOptions,\n BaseHttpDataSource\n} from '@rxap/data-source/http';\nimport {\n RxapDataSource,\n BaseDataSourceViewer,\n RXAP_DATA_SOURCE_REFRESH\n} from '@rxap/data-source';\nimport {\n Observable,\n throwError,\n Subject,\n EMPTY\n} from 'rxjs';\nimport {\n map,\n tap,\n retry,\n filter,\n catchError,\n timeout,\n take\n} from 'rxjs/operators';\nimport { Mixin } from '@rxap/mixin';\nimport { isDefined } from '@rxap/utilities/rxjs';\n\nexport interface OpenApiDataSourceMetadata<PathParams = KeyValue, Body = any | null> extends Partial<HttpDataSourceMetadata<PathParams, Body>> {\n\n /**\n * The operation object with path and method\n */\n operation?: OperationObjectWithMetadata;\n\n /**\n * The index of the server object in the servers array in the open api config\n */\n serverIndex?: number;\n\n /**\n * The operation id\n */\n id: string;\n\n strict?: boolean;\n\n}\n\nexport interface OpenApiDataSourceViewer<Parameters = any>\n extends BaseDataSourceViewer<Parameters> {\n parameters?: Parameters;\n}\n\nexport function RxapOpenApiDataSource(operationIdOrMetadata: string | OpenApiDataSourceMetadata, serverIndex: number = 0) {\n const metadata = typeof operationIdOrMetadata === 'string' ? { id: operationIdOrMetadata, serverIndex } : operationIdOrMetadata;\n return function(target: any) {\n RxapDataSource(metadata)(target);\n };\n}\n\nexport interface OpenApiDataSource<Response = any, Parameters = any> extends SchemaValidationMixin<Response, Parameters> {}\n\n@Mixin(SchemaValidationMixin)\n@Injectable()\nexport class OpenApiDataSource<Response = any, Parameters = any>\n extends BaseHttpDataSource<Response> {\n\n public get operation(): OperationObjectWithMetadata {\n return this.metadata.operation;\n }\n\n protected readonly strict: boolean = false;\n protected readonly disableSchemaValidation: boolean = false;\n protected readonly disableValidation: boolean = false;\n\n constructor(\n @Inject(HttpClient)\n http: HttpClient,\n @Inject(OpenApiConfigService)\n private readonly openApiConfigService: OpenApiConfigService,\n @Optional()\n @Inject(DEFAULT_OPEN_API_DATA_SOURCE_META_DATA)\n metadata: OpenApiDataSourceMetadata | null = null,\n @Optional()\n @Inject(RXAP_DATA_SOURCE_REFRESH)\n refresh$: Subject<HttpDataSourceOptions> | null = null,\n @Optional()\n @Inject(RXAP_OPEN_API_STRICT_VALIDATOR)\n strict: boolean | null = null,\n @Optional()\n @Inject(DISABLE_SCHEMA_VALIDATION)\n disableSchemaValidation: boolean | null = null,\n @Optional()\n @Inject(DISABLE_VALIDATION)\n disableValidation: boolean | null = null\n ) {\n super(http, metadata as any);\n let operation: OperationObjectWithMetadata;\n if (!this.metadata.operation) {\n this.metadata.operation = operation = openApiConfigService.getOperation(this.metadata.id);\n } else {\n operation = this.metadata.operation;\n }\n\n if (operation.method !== 'GET') {\n throw new Error('OpenApi DataSource only supports GET Operations!');\n }\n\n this.applyMetadata({\n id: operation.operationId,\n url: () => joinPath(openApiConfigService.getBaseUrl(this.metadata.serverIndex), operation.path),\n method: 'GET'\n });\n\n this.strict = strict || this.metadata.strict || false;\n this.disableSchemaValidation = disableSchemaValidation || this.metadata.disableSchemaValidation || false;\n this.disableValidation = disableValidation || this.metadata.disableValidation || false;\n\n }\n\n public derive<D = Response>(\n id: string,\n metadata: Partial<OpenApiDataSourceMetadata> = this.metadata,\n isolated: boolean = false\n ): OpenApiDataSource<D, Parameters> {\n return new OpenApiDataSource<D, Parameters>(\n this.http,\n this.openApiConfigService,\n { ...deepMerge(this.metadata, metadata), id },\n isolated ? null : this.refresh$\n );\n }\n\n public connect(viewer: OpenApiDataSourceViewer<Parameters>): Observable<Response> {\n\n\n if (viewer.parameters) {\n if (!this.disableValidation) {\n this.validateParameters(this.operation, viewer.parameters, this.strict);\n }\n } else {\n if (viewer.viewChange === EMPTY || viewer.viewChange === undefined) {\n // set the viewer parameters to an empty parameter and test if that\n // is valid.\n viewer.parameters = {} as any;\n if (!this.disableValidation) {\n this.validateParameters(this.operation, viewer.parameters, this.strict);\n }\n }\n }\n\n return super.connect({\n ...viewer,\n ...this.buildHttpOptions(this.operation, viewer.parameters),\n // if the view change is an empty observable. Then dont apply the pipe logic\n // else the http request is never triggered\n viewChange: viewer.viewChange === EMPTY ? viewer.viewChange : viewer.viewChange?.pipe(\n tap(parameters => {\n if (!this.disableValidation) {\n this.validateParameters(this.operation, parameters, this.strict);\n }\n }),\n map(parameters => this.buildHttpOptions(this.operation, parameters))\n )\n });\n\n }\n\n protected buildRequest(options: HttpDataSourceOptions): Observable<Response> {\n return this.http.request<Response>(this.buildHttpRequest(options)).pipe(\n retry(this.metadata.retry ?? 0),\n catchError((response: HttpErrorResponse) => {\n this.interceptors?.forEach(interceptor => interceptor\n .next({ response, options })\n );\n return throwError(response);\n }),\n filter((event: any) => event.type === HttpEventType.Response),\n tap((response: HttpResponse<Response>) => {\n if (!this.disableValidation) {\n this.validateResponse(this.operation, response, this.strict);\n }\n }),\n tap((response: HttpResponse<Response>) => {\n this.interceptors?.forEach(interceptor => interceptor\n .next({ response, options })\n );\n }),\n map((event: HttpResponse<Response>) => event.body),\n isDefined(),\n take(1),\n timeout(this.timeout)\n );\n }\n\n}\n","import {\n Injectable,\n Inject\n} from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { OpenApiDataSource } from './open-api.data-source';\nimport { OpenApiConfigService } from '@rxap/open-api';\n\n@Injectable({ providedIn: 'root' })\nexport class OpenApiDataSourceLoader {\n\n constructor(\n @Inject(OpenApiConfigService) public readonly openApiConfig: OpenApiConfigService,\n @Inject(HttpClient) public readonly http: HttpClient\n ) {}\n\n public load(definitionId: string): OpenApiDataSource | null {\n\n const operation = this.openApiConfig.getOperation(definitionId);\n\n if (operation) {\n return new OpenApiDataSource(\n this.http,\n this.openApiConfig,\n {\n id: definitionId,\n operation\n }\n );\n }\n\n return null;\n }\n\n}\n","import { RxapOpenApiError } from '@rxap/open-api';\n\nexport class RxapOpenApiDataSourceError extends RxapOpenApiError {\n\n constructor(message: string, code?: string, scope?: string) {\n super(message, code, scope);\n this.addSubPackageName('data-source');\n }\n\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;SA+EgB,qBAAqB,CAAC,qBAAyD,EAAE,cAAsB,CAAC;IACtH,MAAM,QAAQ,GAAG,OAAO,qBAAqB,KAAK,QAAQ,GAAG,EAAE,EAAE,EAAE,qBAAqB,EAAE,WAAW,EAAE,GAAG,qBAAqB,CAAC;IAChI,OAAO,UAAS,MAAW;QACzB,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;KAClC,CAAC;AACJ,CAAC;IAMY,iBAAiB,+BAAjB,iBACX,SAAQ,kBAA4B;IAUpC,YAEI,IAAgB,EAED,oBAA0C,EAGzD,WAA6C,IAAI,EAGjD,WAAkD,IAAI,EAGxD,SAAyB,IAAI,EAG7B,0BAA0C,IAAI,EAG5C,oBAAoC,IAAI;QAE1C,KAAK,CAAC,IAAI,EAAE,QAAe,CAAC,CAAC;QAjBZ,yBAAoB,GAApB,oBAAoB,CAAsB;QAR1C,WAAM,GAAY,KAAK,CAAC;QACxB,4BAAuB,GAAY,KAAK,CAAC;QACzC,sBAAiB,GAAY,KAAK,CAAC;QAwBpD,IAAI,SAAsC,CAAC;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ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;0BAEjB,MAAM;2BAAC,oBAAoB;;0BAE3B,QAAQ;;0BACR,MAAM;2BAAC,sCAAsC;;0BAE7C,QAAQ;;0BACR,MAAM;2BAAC,wBAAwB;;0BAE/B,QAAQ;;0BACR,MAAM;2BAAC,8BAA8B;;0BAErC,QAAQ;;0BACR,MAAM;2BAAC,yBAAyB;;0BAEhC,QAAQ;;0BACR,MAAM;2BAAC,kBAAkB;;;MC9GjB,uBAAuB;IAElC,YACgD,aAAmC,EAC7C,IAAgB;QADN,kBAAa,GAAb,aAAa,CAAsB;QAC7C,SAAI,GAAJ,IAAI,CAAY;KAClD;IAEG,IAAI,CAAC,YAAoB;QAE9B,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAEhE,IAAI,SAAS,EAAE;YACb,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,aAAa,EAClB;gBACE,EAAE,EAAE,YAAY;gBAChB,SAAS;aACV,CACF,CAAC;SACH;QAED,OAAO,IAAI,CAAC;KACb;;oHAvBU,uBAAuB,kBAGxB,oBAAoB,aACpB,UAAU;wHAJT,uBAAuB,cADV,MAAM;2FACnB,uBAAuB;kBADnC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAI7B,MAAM;2BAAC,oBAAoB;;0BAC3B,MAAM;2BAAC,UAAU;;;MCXT,0BAA2B,SAAQ,gBAAgB;IAE9D,YAAY,OAAe,EAAE,IAAa,EAAE,KAAc;QACxD,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;KACvC;;;ACPH;;;;;;"}
@@ -2,24 +2,35 @@ import * as i0 from '@angular/core';
2
2
  import { Injector, Injectable, Inject, Optional } from '@angular/core';
3
3
  import * as i1 from '@angular/common/http';
4
4
  import { HttpEventType, HttpClient } from '@angular/common/http';
5
- import { __awaiter, __decorate, __metadata } from 'tslib';
5
+ import { __decorate, __metadata } from 'tslib';
6
6
  import * as i2 from '@rxap/open-api';
7
7
  import { OpenApiConfigService, DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA, RXAP_OPEN_API_STRICT_VALIDATOR, DISABLE_SCHEMA_VALIDATION, DISABLE_VALIDATION, SchemaValidationMixin, RxapOpenApiError } from '@rxap/open-api';
8
8
  import { BaseHttpRemoteMethod } from '@rxap/remote-method/http';
9
9
  import { RxapRemoteMethod } from '@rxap/remote-method';
10
- import { joinPath } from '@rxap/utilities';
10
+ import { JoinPath } from '@rxap/utilities';
11
11
  import { retry, catchError, filter, tap, take, timeout } from 'rxjs/operators';
12
12
  import { throwError } from 'rxjs';
13
13
  import { Mixin } from '@rxap/mixin';
14
14
 
15
- function RxapOpenApiRemoteMethod(operationId, serverIndex = 0) {
15
+ function RxapOpenApiRemoteMethod(operationOrId, serverIndex = 0) {
16
16
  return function (target) {
17
- RxapRemoteMethod({ id: operationId, serverIndex })(target);
17
+ const id = typeof operationOrId === 'string' ? operationOrId : (operationOrId.operation.operationId ?? operationOrId.fallbackId);
18
+ if (!id) {
19
+ throw new Error('The operationId for the open api remote method is not defined');
20
+ }
21
+ const metadata = {
22
+ id,
23
+ serverIndex
24
+ };
25
+ if (typeof operationOrId !== 'string') {
26
+ metadata.operation = operationOrId.operation;
27
+ metadata.serverId = operationOrId.serverId;
28
+ }
29
+ RxapRemoteMethod(metadata)(target);
18
30
  };
19
31
  }
20
32
  let OpenApiRemoteMethod = class OpenApiRemoteMethod extends BaseHttpRemoteMethod {
21
33
  constructor(http, injector, openApiConfigService, metadata = null, strict = null, disableSchemaValidation = null, disableValidation = null) {
22
- var _a, _b;
23
34
  super(http, injector, metadata);
24
35
  this.strict = false;
25
36
  this.disableSchemaValidation = false;
@@ -33,10 +44,10 @@ let OpenApiRemoteMethod = class OpenApiRemoteMethod extends BaseHttpRemoteMethod
33
44
  }
34
45
  this.applyMetadata({
35
46
  id: operation.operationId,
36
- url: () => joinPath(openApiConfigService.getBaseUrl(this.metadata.serverIndex), operation.path),
47
+ url: () => JoinPath(openApiConfigService.getBaseUrl(this.metadata.serverIndex, this.metadata.serverId), operation.path),
37
48
  method: operation.method,
38
- withCredentials: (_a = this.metadata.withCredentials) !== null && _a !== void 0 ? _a : true,
39
- ignoreUndefined: (_b = this.metadata.ignoreUndefined) !== null && _b !== void 0 ? _b : true,
49
+ withCredentials: this.metadata.withCredentials ?? true,
50
+ ignoreUndefined: this.metadata.ignoreUndefined ?? true,
40
51
  });
41
52
  this.strict = strict || this.metadata.strict || false;
42
53
  this.disableSchemaValidation = disableSchemaValidation || this.metadata.disableSchemaValidation || false;
@@ -45,46 +56,40 @@ let OpenApiRemoteMethod = class OpenApiRemoteMethod extends BaseHttpRemoteMethod
45
56
  get operation() {
46
57
  return this.metadata.operation;
47
58
  }
48
- _call(args = {}) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- if (!this.disableValidation) {
51
- this.validateParameters(this.operation, args.parameters, this.strict);
52
- this.validateRequestBody(this.operation, args.requestBody, this.strict);
53
- }
54
- const response = yield this._callWithResponse(args);
55
- if (response.body) {
56
- return response.body;
57
- }
58
- console.warn('The response body is empty!');
59
- return null;
60
- });
59
+ async _call(args = {}) {
60
+ if (!this.disableValidation) {
61
+ this.validateParameters(this.operation, args.parameters, this.strict);
62
+ this.validateRequestBody(this.operation, args.requestBody, this.strict);
63
+ }
64
+ const response = await this._callWithResponse(args);
65
+ if (response.body) {
66
+ return response.body;
67
+ }
68
+ console.warn('The response body is empty!');
69
+ return null;
61
70
  }
62
71
  /**
63
72
  * Instead of returning the response body the full response object is returned
64
73
  */
65
- callWithResponse(args = {}) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- this.init();
68
- this.executionsInProgress$.increase();
69
- const result = yield this._callWithResponse(args);
70
- this.executionsInProgress$.decrease();
71
- if (result.body) {
72
- this.executed$.next(result.body);
73
- this.executed(result.body);
74
- }
75
- return result;
76
- });
74
+ async callWithResponse(args = {}) {
75
+ this.init();
76
+ this.executionsInProgress$.increase();
77
+ const result = await this._callWithResponse(args);
78
+ this.executionsInProgress$.decrease();
79
+ if (result.body) {
80
+ this.executed$.next(result.body);
81
+ this.executed(result.body);
82
+ }
83
+ return result;
77
84
  }
78
85
  // TODO : update to the new call method concept (the remove of the _call method concept)
79
86
  _callWithResponse(args = {}) {
80
- var _a;
81
87
  if (!this.disableValidation) {
82
88
  this.validateParameters(this.operation, args.parameters, this.strict);
83
89
  this.validateRequestBody(this.operation, args.requestBody, this.strict);
84
90
  }
85
- return this.http.request(this.updateRequest(this.buildHttpOptions(this.operation, args.parameters, args.requestBody, this.metadata.ignoreUndefined))).pipe(retry((_a = this.metadata.retry) !== null && _a !== void 0 ? _a : 0), catchError((response) => {
86
- var _a;
87
- (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.forEach(interceptor => interceptor
91
+ return this.http.request(this.updateRequest(this.buildHttpOptions(this.operation, args.parameters, args.requestBody, this.metadata.ignoreUndefined))).pipe(retry(this.metadata.retry ?? 0), catchError((response) => {
92
+ this.interceptors?.forEach(interceptor => interceptor
88
93
  .next({ response, parameters: args.parameters, requestBody: args.requestBody }));
89
94
  return throwError(response);
90
95
  }), filter((event) => event.type === HttpEventType.Response), tap((response) => {
@@ -92,21 +97,20 @@ let OpenApiRemoteMethod = class OpenApiRemoteMethod extends BaseHttpRemoteMethod
92
97
  this.validateResponse(this.operation, response, this.strict);
93
98
  }
94
99
  }), tap((response) => {
95
- var _a;
96
- (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.forEach(interceptor => interceptor
100
+ this.interceptors?.forEach(interceptor => interceptor
97
101
  .next({ response, parameters: args.parameters, requestBody: args.requestBody }));
98
102
  }), take(1), timeout(this.timeout)).toPromise();
99
103
  }
100
104
  };
101
- OpenApiRemoteMethod.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiRemoteMethod, deps: [{ token: HttpClient }, { token: Injector }, { token: OpenApiConfigService }, { token: DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA, optional: true }, { token: RXAP_OPEN_API_STRICT_VALIDATOR, optional: true }, { token: DISABLE_SCHEMA_VALIDATION, optional: true }, { token: DISABLE_VALIDATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
102
- OpenApiRemoteMethod.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiRemoteMethod });
105
+ OpenApiRemoteMethod.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiRemoteMethod, deps: [{ token: HttpClient }, { token: Injector }, { token: OpenApiConfigService }, { token: DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA, optional: true }, { token: RXAP_OPEN_API_STRICT_VALIDATOR, optional: true }, { token: DISABLE_SCHEMA_VALIDATION, optional: true }, { token: DISABLE_VALIDATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
106
+ OpenApiRemoteMethod.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiRemoteMethod });
103
107
  OpenApiRemoteMethod = __decorate([
104
108
  Mixin(SchemaValidationMixin),
105
109
  __metadata("design:paramtypes", [HttpClient,
106
110
  Injector,
107
111
  OpenApiConfigService, Object, Object, Object, Object])
108
112
  ], OpenApiRemoteMethod);
109
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiRemoteMethod, decorators: [{
113
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiRemoteMethod, decorators: [{
110
114
  type: Injectable
111
115
  }], ctorParameters: function () { return [{ type: i1.HttpClient, decorators: [{
112
116
  type: Inject,
@@ -156,9 +160,9 @@ class OpenApiRemoteMethodLoader {
156
160
  return null;
157
161
  }
158
162
  }
159
- OpenApiRemoteMethodLoader.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiRemoteMethodLoader, deps: [{ token: OpenApiConfigService }, { token: HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
160
- OpenApiRemoteMethodLoader.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiRemoteMethodLoader, providedIn: 'root' });
161
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OpenApiRemoteMethodLoader, decorators: [{
163
+ OpenApiRemoteMethodLoader.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiRemoteMethodLoader, deps: [{ token: OpenApiConfigService }, { token: HttpClient }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
164
+ OpenApiRemoteMethodLoader.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiRemoteMethodLoader, providedIn: 'root' });
165
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiRemoteMethodLoader, decorators: [{
162
166
  type: Injectable,
163
167
  args: [{ providedIn: 'root' }]
164
168
  }], ctorParameters: function () { return [{ type: i2.OpenApiConfigService, decorators: [{
@@ -181,4 +185,4 @@ class RxapOpenApiRemoteMethodError extends RxapOpenApiError {
181
185
  */
182
186
 
183
187
  export { OpenApiRemoteMethod, OpenApiRemoteMethodLoader, RxapOpenApiRemoteMethod, RxapOpenApiRemoteMethodError };
184
- //# sourceMappingURL=rxap-open-api-remote-method.js.map
188
+ //# sourceMappingURL=rxap-open-api-remote-method.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rxap-open-api-remote-method.mjs","sources":["../../../../libs/open-api/remote-method/src/lib/open-api.remote-method.ts","../../../../libs/open-api/remote-method/src/lib/open-api-remote-method.loader.ts","../../../../libs/open-api/remote-method/src/lib/error.ts","../../../../libs/open-api/remote-method/src/rxap-open-api-remote-method.ts"],"sourcesContent":["import {\n Inject,\n Injector,\n Optional,\n Injectable\n} from '@angular/core';\nimport {\n HttpClient,\n HttpResponse,\n HttpEventType,\n HttpErrorResponse\n} from '@angular/common/http';\nimport {\n OperationObjectWithMetadata,\n OpenApiConfigService,\n SchemaValidationMixin,\n RXAP_OPEN_API_STRICT_VALIDATOR,\n DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA,\n DISABLE_SCHEMA_VALIDATION,\n DISABLE_VALIDATION\n} from '@rxap/open-api';\nimport { BaseHttpRemoteMethod } from '@rxap/remote-method/http';\nimport {\n BaseRemoteMethodMetadata,\n RxapRemoteMethod\n} from '@rxap/remote-method';\nimport { JoinPath } from '@rxap/utilities';\nimport {\n filter,\n timeout,\n retry,\n catchError,\n tap,\n take\n} from 'rxjs/operators';\nimport { throwError } from 'rxjs';\nimport { Mixin } from '@rxap/mixin';\n\nexport interface OperationForMetadata {\n operation: OperationObjectWithMetadata;\n /**\n * used to specify the target server for the reset api operation\n */\n serverId?: string;\n /**\n * the fallback id used if the operation does not have a operationId\n */\n fallbackId?: string;\n}\n\nexport function RxapOpenApiRemoteMethod(operationOrId: string | OperationForMetadata, serverIndex: number = 0) {\n return function(target: any) {\n const id = typeof operationOrId === 'string' ? operationOrId : (operationOrId.operation.operationId ?? operationOrId.fallbackId);\n if (!id) {\n throw new Error('The operationId for the open api remote method is not defined');\n }\n const metadata: OpenApiRemoteMethodMetadata = {\n id,\n serverIndex\n };\n if (typeof operationOrId !== 'string') {\n metadata.operation = operationOrId.operation;\n metadata.serverId = operationOrId.serverId;\n }\n RxapRemoteMethod(metadata)(target);\n };\n}\n\nexport interface OpenApiRemoteMethodMetadata extends BaseRemoteMethodMetadata {\n /**\n * The operation object with path and method\n */\n operation?: OperationObjectWithMetadata;\n /**\n * The index of the server object in the servers array in the open api config\n */\n serverIndex?: number;\n /**\n * used to specify the target server for the reset api operation\n */\n serverId?: string;\n id: string;\n}\n\nexport interface OpenApiRemoteMethodParameter<Parameters extends Record<string, any> | void = any, RequestBody = any> {\n parameters?: Parameters,\n requestBody?: RequestBody\n}\n\nexport interface OpenApiRemoteMethod<Response = any, Parameters extends Record<string, any> | void = any, RequestBody = any>\n extends SchemaValidationMixin<Response, Parameters, RequestBody> {}\n\n@Mixin(SchemaValidationMixin)\n@Injectable()\nexport class OpenApiRemoteMethod<Response = any, Parameters extends Record<string, any> | void = any, RequestBody = any>\n extends BaseHttpRemoteMethod<Response, any, OpenApiRemoteMethodParameter<Parameters, RequestBody>> {\n\n public get operation(): OperationObjectWithMetadata {\n return this.metadata.operation;\n }\n\n private readonly strict: boolean = false;\n protected readonly disableSchemaValidation: boolean = false;\n protected readonly disableValidation: boolean = false;\n\n constructor(\n @Inject(HttpClient) http: HttpClient,\n @Inject(Injector) injector: Injector,\n @Inject(OpenApiConfigService) openApiConfigService: OpenApiConfigService,\n @Optional()\n @Inject(DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA)\n metadata: OpenApiRemoteMethodMetadata | null = null,\n @Optional()\n @Inject(RXAP_OPEN_API_STRICT_VALIDATOR)\n strict: boolean | null = null,\n @Optional()\n @Inject(DISABLE_SCHEMA_VALIDATION)\n disableSchemaValidation: boolean | null = null,\n @Optional()\n @Inject(DISABLE_VALIDATION)\n disableValidation: boolean | null = null\n ) {\n super(http, injector, metadata);\n let operation: OperationObjectWithMetadata & { serverId?: string };\n if (!this.metadata.operation) {\n this.metadata.operation = operation = openApiConfigService.getOperation(this.metadata.id);\n } else {\n operation = this.metadata.operation;\n }\n this.applyMetadata({\n id: operation.operationId,\n url: () => JoinPath(openApiConfigService.getBaseUrl(this.metadata.serverIndex, this.metadata.serverId), operation.path),\n method: operation.method as any,\n withCredentials: this.metadata.withCredentials ?? true,\n ignoreUndefined: this.metadata.ignoreUndefined ?? true,\n });\n this.strict = strict || this.metadata.strict || false;\n this.disableSchemaValidation = disableSchemaValidation || this.metadata.disableSchemaValidation || false;\n this.disableValidation = disableValidation || this.metadata.disableValidation || false;\n }\n\n protected async _call(args: OpenApiRemoteMethodParameter<Parameters, RequestBody> = {}): Promise<Response> {\n\n if (!this.disableValidation) {\n this.validateParameters(this.operation, args.parameters, this.strict);\n this.validateRequestBody(this.operation, args.requestBody, this.strict);\n }\n\n const response = await this._callWithResponse(args);\n\n if (response.body) {\n return response.body;\n }\n\n console.warn('The response body is empty!');\n return null as any;\n }\n\n /**\n * Instead of returning the response body the full response object is returned\n */\n public async callWithResponse(args: OpenApiRemoteMethodParameter<Parameters, RequestBody> = {}): Promise<HttpResponse<Response>> {\n this.init();\n this.executionsInProgress$.increase();\n const result = await this._callWithResponse(args);\n this.executionsInProgress$.decrease();\n if (result.body) {\n this.executed$.next(result.body);\n this.executed(result.body);\n }\n return result;\n }\n\n // TODO : update to the new call method concept (the remove of the _call method concept)\n public _callWithResponse(args: OpenApiRemoteMethodParameter<Parameters, RequestBody> = {}): Promise<HttpResponse<Response>> {\n\n if (!this.disableValidation) {\n this.validateParameters(this.operation, args.parameters, this.strict);\n this.validateRequestBody(this.operation, args.requestBody, this.strict);\n }\n\n return this.http.request<Response>(this.updateRequest(this.buildHttpOptions(this.operation, args.parameters, args.requestBody, this.metadata.ignoreUndefined))).pipe(\n retry(this.metadata.retry ?? 0),\n catchError((response: HttpErrorResponse) => {\n this.interceptors?.forEach(interceptor => interceptor\n .next({ response, parameters: args.parameters, requestBody: args.requestBody })\n );\n return throwError(response);\n }),\n filter((event: any) => event.type === HttpEventType.Response),\n tap((response: HttpResponse<Response>) => {\n if (this.disableValidation) {\n this.validateResponse(this.operation, response, this.strict);\n }\n }),\n tap((response: HttpResponse<Response>) => {\n this.interceptors?.forEach(interceptor => interceptor\n .next({ response, parameters: args.parameters, requestBody: args.requestBody })\n );\n }),\n take(1),\n timeout(this.timeout)\n ).toPromise();\n\n }\n\n}\n","import {\n Injectable,\n Injector,\n Inject\n} from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { OpenApiRemoteMethod } from './open-api.remote-method';\nimport { OpenApiConfigService } from '@rxap/open-api';\n\n@Injectable({ providedIn: 'root' })\nexport class OpenApiRemoteMethodLoader {\n\n constructor(\n @Inject(OpenApiConfigService) public readonly openApiConfig: OpenApiConfigService,\n @Inject(HttpClient) public readonly http: HttpClient,\n public readonly injector: Injector\n ) {}\n\n public load(definitionId: string): OpenApiRemoteMethod | null {\n const operation = this.openApiConfig.getOperation(definitionId);\n\n if (operation) {\n\n return new OpenApiRemoteMethod(\n this.http,\n this.injector,\n this.openApiConfig,\n {\n id: definitionId,\n operation\n }\n );\n\n }\n\n return null;\n\n }\n\n}\n","import { RxapOpenApiError } from '@rxap/open-api';\n\nexport class RxapOpenApiRemoteMethodError extends RxapOpenApiError {\n\n constructor(message: string, code?: string, scope?: string) {\n super(message, code, scope);\n this.addSubPackageName('remote-method');\n }\n\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;;;;SAkDgB,uBAAuB,CAAC,aAA4C,EAAE,cAAsB,CAAC;IAC3G,OAAO,UAAS,MAAW;QACzB,MAAM,EAAE,GAAG,OAAO,aAAa,KAAK,QAAQ,GAAG,aAAa,IAAI,aAAa,CAAC,SAAS,CAAC,WAAW,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;QACjI,IAAI,CAAC,EAAE,EAAE;YACP,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;SAClF;QACD,MAAM,QAAQ,GAAgC;YAC5C,EAAE;YACF,WAAW;SACZ,CAAC;QACF,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;YACrC,QAAQ,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC;YAC7C,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC;SAC5C;QACD,gBAAgB,CAAC,Q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AClB;gBACE,EAAE,EAAE,YAAY;gBAChB,SAAS;aACV,CACF,CAAC;SAEH;QAED,OAAO,IAAI,CAAC;KAEb;;sHA3BU,yBAAyB,kBAG1B,oBAAoB,aACpB,UAAU;0HAJT,yBAAyB,cADZ,MAAM;2FACnB,yBAAyB;kBADrC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAI7B,MAAM;2BAAC,oBAAoB;;0BAC3B,MAAM;2BAAC,UAAU;;;MCZT,4BAA6B,SAAQ,gBAAgB;IAEhE,YAAY,OAAe,EAAE,IAAa,EAAE,KAAc;QACxD,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;KACzC;;;ACPH;;;;;;"}
@@ -1,10 +1,194 @@
1
- import { coerceArray, isPromiseLike, IsRecord, clone } from '@rxap/utilities';
2
- import { isDevMode } from '@angular/core';
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Injectable, Optional, Inject, isDevMode } from '@angular/core';
3
+ import { RxapError, coerceArray, IsRecord, clone, isPromiseLike } from '@rxap/utilities';
3
4
  import * as Ajv from 'ajv-oai';
4
5
  import { HttpParams, HttpHeaders } from '@angular/common/http';
5
- import { NotContainsReferenceObjects, IsReferenceObject } from './utilities';
6
- import { RxapOpenApiError } from './error';
7
- export class SchemaValidationMixin {
6
+
7
+ const RXAP_OPEN_API_CONFIG = new InjectionToken('rxap/open-api/config');
8
+ const RXAP_OPEN_API_STRICT_VALIDATOR = new InjectionToken('rxap/open-api/strict-validator');
9
+ const DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA = new InjectionToken('rxap/open-api/default-remote-method-meta-data');
10
+ const DEFAULT_OPEN_API_DATA_SOURCE_META_DATA = new InjectionToken('rxap/open-api/default-data-source-meta-data');
11
+ const DISABLE_SCHEMA_VALIDATION = new InjectionToken('rxap/open-api/disable-schema-validation');
12
+ const DISABLE_VALIDATION = new InjectionToken('rxap/open-api/disable-validation');
13
+
14
+ class RxapOpenApiError extends RxapError {
15
+ constructor(message, code, scope) {
16
+ super('@rxap/open-api', message, code ?? '', scope);
17
+ }
18
+ }
19
+
20
+ function IsReferenceObject(obj) {
21
+ return !!obj && obj.hasOwnProperty('$ref');
22
+ }
23
+ function NotContainsReferenceObjects(array) {
24
+ return !!array && array.every(item => !IsReferenceObject(item) && !!item);
25
+ }
26
+ function IsOpenApiV3(obj) {
27
+ return !!obj && obj.hasOwnProperty('openapi') && obj.openapi.match(/^3\./);
28
+ }
29
+ function AssertOpenApiV3(obj) {
30
+ if (!IsOpenApiV3(obj)) {
31
+ throw new RxapOpenApiError('Only openapi version 3.x.x is supported');
32
+ }
33
+ }
34
+
35
+ class OpenApiConfigService {
36
+ constructor(config = null) {
37
+ this.defaultServerIndex = OpenApiConfigService.DefaultServerIndex;
38
+ this._operations = null;
39
+ this.serverConfigMap = new Map();
40
+ this._config = null;
41
+ config = config ?? OpenApiConfigService.Config;
42
+ if (config) {
43
+ this._config = config;
44
+ this._operations = OpenApiConfigService.LoadOperations(config);
45
+ }
46
+ }
47
+ /**
48
+ * Used to load the app open api config from a remote resource.
49
+ *
50
+ * Promise.all([ OpenApiDataSourceLoader.Load() ])
51
+ * .then(() => platformBrowserDynamic().bootstrapModule(AppModule))
52
+ * .catch(err => console.error(err))
53
+ *
54
+ */
55
+ static async Load(openApiUrl = 'openapi.json') {
56
+ if (!openApiUrl) {
57
+ throw new Error('The open api url is not defined!');
58
+ }
59
+ let config = null;
60
+ try {
61
+ const response = await fetch(openApiUrl);
62
+ config = await response.json();
63
+ }
64
+ catch (error) {
65
+ console.debug(`Could not load the open api config from '${openApiUrl}'!`, error);
66
+ console.error(`Could not load the open api config from '${openApiUrl}'!`, error.message);
67
+ }
68
+ if (config) {
69
+ const expandedConfig = await this.ExpandOpenApi(config);
70
+ AssertOpenApiV3(expandedConfig);
71
+ this.Config = expandedConfig;
72
+ }
73
+ else {
74
+ this.Config = null;
75
+ }
76
+ }
77
+ static GetOperation(operationId) {
78
+ if (!this.Config) {
79
+ throw new Error('Could not load open api config');
80
+ }
81
+ if (!this._operations) {
82
+ this._operations = this.LoadOperations(this.Config);
83
+ }
84
+ if (!this._operations.has(operationId)) {
85
+ throw new Error(`The operation '${operationId}' is not defined in the openapi-json`);
86
+ }
87
+ return this._operations.get(operationId);
88
+ }
89
+ static LoadOperations(config) {
90
+ const operations = new Map();
91
+ Object.entries(config.paths)
92
+ .filter((item) => item[0] !== undefined)
93
+ .filter(([_, methods]) => methods &&
94
+ Object.keys(methods).some((method) => ['get', 'put', 'post', 'delete', 'patch'].includes(method)))
95
+ .forEach(([path, methods]) => Object.entries(methods)
96
+ .filter((item) => item[0] !== undefined)
97
+ .forEach(([method, operation]) => {
98
+ if (!operation.operationId) {
99
+ throw new Error('The OpenApu OperationId is not defined');
100
+ }
101
+ if (operations.has(operation.operationId)) {
102
+ throw new Error(`The OpenApi Operation '${operation.operationId}' is already defined.`);
103
+ }
104
+ operations.set(operation.operationId, {
105
+ ...operation,
106
+ path: path,
107
+ method: method.toUpperCase(),
108
+ });
109
+ }));
110
+ return operations;
111
+ }
112
+ static GetBaseUrl(config, serverIndex = this.DefaultServerIndex) {
113
+ const server = config.servers ? config.servers[serverIndex] : null;
114
+ if (!server) {
115
+ console.debug(`Could not extract the server config with the index '${serverIndex}' from the open api config`, config);
116
+ throw new Error(`Could not extract the server config with the index '${serverIndex}' from the open api config`);
117
+ }
118
+ return server.url;
119
+ }
120
+ /**
121
+ * Replaces all $ref with the concrete definition
122
+ *
123
+ * @param config
124
+ * @private
125
+ */
126
+ static ExpandOpenApi(config) {
127
+ return Promise.resolve(config);
128
+ }
129
+ get config() {
130
+ if (!this._config) {
131
+ throw new Error('Could not load open api config');
132
+ }
133
+ return this._config;
134
+ }
135
+ getOperation(operationId) {
136
+ if (!this._operations) {
137
+ if (!this._config) {
138
+ throw new Error('The operations map is not loaded and the config object is not loaded');
139
+ }
140
+ this._operations = OpenApiConfigService.LoadOperations(this._config);
141
+ }
142
+ if (!this._operations.has(operationId)) {
143
+ console.debug(`The operation '${operationId}' is not defined in the openapi-json`, this.config);
144
+ throw new Error(`The operation '${operationId}' is not defined in the openapi-json`);
145
+ }
146
+ return this._operations.get(operationId);
147
+ }
148
+ getBaseUrl(serverIndex = this.defaultServerIndex, serverId) {
149
+ let serverConfig;
150
+ if (!serverId && this._config?.servers) {
151
+ serverConfig = this._config.servers[serverIndex];
152
+ }
153
+ if (this.serverConfigMap.has(serverId)) {
154
+ serverConfig = this.serverConfigMap.get(serverId)[serverIndex];
155
+ }
156
+ if (!serverConfig) {
157
+ throw new Error(`Could not determine the base url with the index: ${serverIndex} and the serverId: ${serverId}`);
158
+ }
159
+ return OpenApiConfigService.GetBaseUrl(this.config, serverIndex);
160
+ }
161
+ insertServer(serverConfig, index = this.defaultServerIndex, serverId) {
162
+ if (this._config) {
163
+ if (!this.config.servers) {
164
+ this.config.servers = [];
165
+ }
166
+ this.config.servers.splice(index, 1, serverConfig);
167
+ }
168
+ if (!this.serverConfigMap.has(serverId)) {
169
+ this.serverConfigMap.set(serverId, []);
170
+ }
171
+ const list = this.serverConfigMap.get(serverId);
172
+ list[index] = serverConfig;
173
+ this.serverConfigMap.set(serverId, list);
174
+ }
175
+ }
176
+ OpenApiConfigService.Config = null;
177
+ OpenApiConfigService.DefaultServerIndex = 0;
178
+ OpenApiConfigService._operations = null;
179
+ OpenApiConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiConfigService, deps: [{ token: RXAP_OPEN_API_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
180
+ OpenApiConfigService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiConfigService, providedIn: 'root' });
181
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: OpenApiConfigService, decorators: [{
182
+ type: Injectable,
183
+ args: [{ providedIn: 'root' }]
184
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
185
+ type: Optional
186
+ }, {
187
+ type: Inject,
188
+ args: [RXAP_OPEN_API_CONFIG]
189
+ }] }]; } });
190
+
191
+ class SchemaValidationMixin {
8
192
  /**
9
193
  * Validates the parameters against the schema specified in the operation object
10
194
  *
@@ -70,7 +254,6 @@ export class SchemaValidationMixin {
70
254
  */
71
255
  validateResponse(operation, response, strict = false) {
72
256
  // region only validate the response if the content type is undefined or application/json
73
- var _a;
74
257
  const contentType = response.headers.get('Content-Type');
75
258
  if (contentType && contentType !== 'application/json') {
76
259
  if (isDevMode()) {
@@ -99,7 +282,7 @@ export class SchemaValidationMixin {
99
282
  // TODO : create schema that validates all parameters at once
100
283
  if (responseObject.content && responseObject.content['application/json'] && responseObject.content['application/json'].schema) {
101
284
  const schema = responseObject.content['application/json'].schema;
102
- const data = (_a = response.body) !== null && _a !== void 0 ? _a : response.data;
285
+ const data = response.body ?? response.data;
103
286
  if (!this.validate(schema, data)) {
104
287
  this.validationError('The response is not valid ageist the operation schema!', strict, schema, data);
105
288
  }
@@ -254,4 +437,10 @@ export class SchemaValidationMixin {
254
437
  }
255
438
  }
256
439
  SchemaValidationMixin.STRICT = false;
257
- //# sourceMappingURL=schema-validation.mixin.js.map
440
+
441
+ /**
442
+ * Generated bundle index. Do not edit.
443
+ */
444
+
445
+ export { AssertOpenApiV3, DEFAULT_OPEN_API_DATA_SOURCE_META_DATA, DEFAULT_OPEN_API_REMOTE_METHOD_META_DATA, DISABLE_SCHEMA_VALIDATION, DISABLE_VALIDATION, IsOpenApiV3, IsReferenceObject, NotContainsReferenceObjects, OpenApiConfigService, RXAP_OPEN_API_CONFIG, RXAP_OPEN_API_STRICT_VALIDATOR, RxapOpenApiError, SchemaValidationMixin };
446
+ //# sourceMappingURL=rxap-open-api.mjs.map