{"version":3,"file":"xxmachina-components-features-command.mjs","sources":["../../../../../packages/@xxmachina/components/src/lib/features/command/command.feature.ts","../../../../../packages/@xxmachina/components/src/lib/features/command/xxmachina-components-features-command.ts"],"sourcesContent":["import { computed, inject, Injectable } from '@angular/core';\nimport { FormBuilder } from '@angular/forms';\nimport { CommandService } from '@xxmachina/components/services/command';\nimport { _computed } from '@ng-atomic/core';\nimport { JsonSchemaFormService } from '@ng-atomic/common/services/form/json-schema';\nimport { OpenApi } from '@xxmachina/common/domain/models';\nimport { Command } from '@xxmachina/common/domain/models';\nimport { OpenApiService } from '@xxmachina/components/services/openapi';\nimport { switchMap, catchError, of, filter, NEVER } from 'rxjs';\nimport { derivedAsync } from 'ngxtension/derived-async';\n\n\n@Injectable({providedIn: 'root'})\nexport class CommandFormBuilder {\n  protected readonly fb = inject(FormBuilder).nonNullable;\n  build() {\n    return this.fb.group({\n      type: ['webApiRequest'],\n      webApiRequest: this.fb.group({\n        apiJsonUrl: [''],\n        serverUrl: [''],\n        path: [''],\n        method: [''],\n      }),\n    });\n  }\n}\n\n@Injectable()\nexport class CommandFeature {\n  readonly fb = inject(FormBuilder);\n  readonly openApiService = inject(OpenApiService);\n  readonly _commandService = inject(CommandService);\n  readonly commandFb = inject(CommandFormBuilder);\n  readonly jsonSchemaFb = inject(JsonSchemaFormService);\n\n  readonly commandForm = computed(() => this.commandFb.build());\n  readonly commandFormValue = derivedAsync(() => this.commandForm().valueChanges, { initialValue: this.commandForm().value });\n  readonly apiJsonUrl = computed(() => this.commandFormValue()?.webApiRequest?.apiJsonUrl);\n  readonly path = computed(() => this.commandFormValue()?.webApiRequest?.path);\n  readonly method = computed(() => this.commandFormValue()?.webApiRequest?.method?.toLowerCase());\n  readonly requestBodySchema = computed(() => this.openApi().getRequestBodySchema(this.path()!, this.method()!));\n  readonly title = computed(() => this.openApi().getSummary(this.path()!, this.method()!));\n  readonly endpointAutoCompleteOptions = computed(() => {\n    return this.openApi().getEndpoints().filter((endpoint) => endpoint.startsWith(this.path()!));\n  });\n  readonly methodOptions = computed(() => {\n    return this.openApi().getMethods(this.commandFormValue()?.webApiRequest?.path ?? '').map((method) => ({\n      name: method.toLocaleUpperCase(), value: method.toLocaleUpperCase()\n    }));\n  });\n\n  readonly openApi = derivedAsync(() => {\n      const url = this.apiJsonUrl();\n      return of(url).pipe(\n        filter((url) => !!url),\n        switchMap(() => this.openApiService.getOpenApi(url!).pipe(\n          catchError((error) => (console.error(error), NEVER)),\n        )),\n      );\n    }, { \n      initialValue: new OpenApi({\n        openapi: '3.0.0',\n        apiJsonUrl: '/api-json',\n        info: { title: 'dummy', version: '1.0.0' },\n        paths: {},\n      }),\n    });\n  readonly form = computed(() => this.jsonSchemaFb.build(this.requestBodySchema(), {fb: this.fb}));\n  readonly extractedFormFieldMap = computed(() => this.jsonSchemaFb.buildFieldMap(this.requestBodySchema(), {\n    merge: {\n      'id': { type: 'hidden' },\n      '__typename': { type: 'hidden' },\n      'kind': { type: 'hidden' },\n    }\n  }));\n\n  hasPermission(command: Command): boolean {\n    return this._commandService.hasPermission(command);\n  }\n\n  execute(command: Command, data: any) {\n    return this._commandService.execute(command, data);\n  }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;MAaa,kBAAkB,CAAA;AACV,IAAA,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,WAAW;IACvD,KAAK,GAAA;AACH,QAAA,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;YACnB,IAAI,EAAE,CAAC,eAAe,CAAC;AACvB,YAAA,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;gBAC3B,UAAU,EAAE,CAAC,EAAE,CAAC;gBAChB,SAAS,EAAE,CAAC,EAAE,CAAC;gBACf,IAAI,EAAE,CAAC,EAAE,CAAC;gBACV,MAAM,EAAE,CAAC,EAAE,CAAC;aACb,CAAC;AACH,SAAA,CAAC;IACJ;uGAZW,kBAAk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