@@ -9,7 +9,6 @@ import { SavedObjectsClientContract } from 'kibana/server';
99import { saveInstalledEsRefs } from '../../packages/install' ;
1010import * as Registry from '../../registry' ;
1111import {
12- Dataset ,
1312 ElasticsearchAssetType ,
1413 EsAssetReference ,
1514 RegistryPackage ,
@@ -24,12 +23,7 @@ interface TransformInstallation {
2423 content : string ;
2524}
2625
27- interface TransformPathDataset {
28- path : string ;
29- dataset : Dataset ;
30- }
31-
32- export const installTransformForDataset = async (
26+ export const installTransform = async (
3327 registryPackage : RegistryPackage ,
3428 paths : string [ ] ,
3529 callCluster : CallESAsCurrentUser ,
@@ -51,53 +45,32 @@ export const installTransformForDataset = async (
5145 callCluster ,
5246 previousInstalledTransformEsAssets . map ( ( asset ) => asset . id )
5347 ) ;
54- // install the latest dataset
55- const datasets = registryPackage . datasets ;
56- if ( ! datasets ?. length ) return [ ] ;
57- const installNameSuffix = `${ registryPackage . version } ` ;
5848
49+ const installNameSuffix = `${ registryPackage . version } ` ;
5950 const transformPaths = paths . filter ( ( path ) => isTransform ( path ) ) ;
6051 let installedTransforms : EsAssetReference [ ] = [ ] ;
6152 if ( transformPaths . length > 0 ) {
62- const transformPathDatasets = datasets . reduce < TransformPathDataset [ ] > ( ( acc , dataset ) => {
63- transformPaths . forEach ( ( path ) => {
64- if ( isDatasetTransform ( path , dataset . path ) ) {
65- acc . push ( { path, dataset } ) ;
66- }
53+ const transformRefs = transformPaths . reduce < EsAssetReference [ ] > ( ( acc , path ) => {
54+ acc . push ( {
55+ id : getTransformNameForInstallation ( registryPackage , path , installNameSuffix ) ,
56+ type : ElasticsearchAssetType . transform ,
6757 } ) ;
58+
6859 return acc ;
6960 } , [ ] ) ;
7061
71- const transformRefs = transformPathDatasets . reduce < EsAssetReference [ ] > (
72- ( acc , transformPathDataset ) => {
73- if ( transformPathDataset ) {
74- acc . push ( {
75- id : getTransformNameForInstallation ( transformPathDataset , installNameSuffix ) ,
76- type : ElasticsearchAssetType . transform ,
77- } ) ;
78- }
79- return acc ;
80- } ,
81- [ ]
82- ) ;
83-
8462 // get and save transform refs before installing transforms
8563 await saveInstalledEsRefs ( savedObjectsClient , registryPackage . name , transformRefs ) ;
8664
87- const transforms : TransformInstallation [ ] = transformPathDatasets . map (
88- ( transformPathDataset : TransformPathDataset ) => {
89- return {
90- installationName : getTransformNameForInstallation (
91- transformPathDataset ,
92- installNameSuffix
93- ) ,
94- content : getAsset ( transformPathDataset . path ) . toString ( 'utf-8' ) ,
95- } ;
96- }
97- ) ;
65+ const transforms : TransformInstallation [ ] = transformPaths . map ( ( path : string ) => {
66+ return {
67+ installationName : getTransformNameForInstallation ( registryPackage , path , installNameSuffix ) ,
68+ content : getAsset ( path ) . toString ( 'utf-8' ) ,
69+ } ;
70+ } ) ;
9871
9972 const installationPromises = transforms . map ( async ( transform ) => {
100- return installTransform ( { callCluster, transform } ) ;
73+ return handleTransformInstall ( { callCluster, transform } ) ;
10174 } ) ;
10275
10376 installedTransforms = await Promise . all ( installationPromises ) . then ( ( results ) => results . flat ( ) ) ;
@@ -123,20 +96,10 @@ export const installTransformForDataset = async (
12396
12497const isTransform = ( path : string ) => {
12598 const pathParts = Registry . pathParts ( path ) ;
126- return pathParts . type === ElasticsearchAssetType . transform ;
99+ return ! path . endsWith ( '/' ) && pathParts . type === ElasticsearchAssetType . transform ;
127100} ;
128101
129- const isDatasetTransform = ( path : string , datasetName : string ) => {
130- const pathParts = Registry . pathParts ( path ) ;
131- return (
132- ! path . endsWith ( '/' ) &&
133- pathParts . type === ElasticsearchAssetType . transform &&
134- pathParts . dataset !== undefined &&
135- datasetName === pathParts . dataset
136- ) ;
137- } ;
138-
139- async function installTransform ( {
102+ async function handleTransformInstall ( {
140103 callCluster,
141104 transform,
142105} : {
@@ -160,9 +123,12 @@ async function installTransform({
160123}
161124
162125const getTransformNameForInstallation = (
163- transformDataset : TransformPathDataset ,
126+ registryPackage : RegistryPackage ,
127+ path : string ,
164128 suffix : string
165129) => {
166- const filename = transformDataset ?. path . split ( '/' ) ?. pop ( ) ?. split ( '.' ) [ 0 ] ;
167- return `${ transformDataset . dataset . type } -${ transformDataset . dataset . name } -${ filename } -${ suffix } ` ;
130+ const pathPaths = path . split ( '/' ) ;
131+ const filename = pathPaths ?. pop ( ) ?. split ( '.' ) [ 0 ] ;
132+ const folderName = pathPaths ?. pop ( ) ;
133+ return `${ registryPackage . name } .${ folderName } -${ filename } -${ suffix } ` ;
168134} ;
0 commit comments