shrub/pkg/npm/api/metadata/index.ts

44 lines
906 B
TypeScript
Raw Normal View History

2021-01-27 08:45:18 +03:00
import { AppName, Path, PatpNoSig, Poke } from "..";
import { Association, Metadata, MetadataUpdateAdd, MetadataUpdateUpdate } from './index.d';
export const action = <T>(data: T): Poke<T> => ({
app: 'metadata-hook',
mark: 'metadata-action',
json: data
});
export const add = (
appName: AppName,
resource: string,
group: string,
metadata: Metadata,
2021-01-27 08:45:18 +03:00
): Poke<MetadataUpdateAdd> => {
return action({
add: {
group,
2021-01-27 08:45:18 +03:00
resource: {
resource,
2021-01-27 08:45:18 +03:00
'app-name': appName
},
metadata
2021-01-27 08:45:18 +03:00
}
});
}
export const update = (
association: Association,
newMetadata: Partial<Metadata>
): Poke<MetadataUpdateAdd> => {
const { resource, metadata, group } = association;
2021-01-27 08:45:18 +03:00
return action({
add: {
group,
2021-01-27 08:45:18 +03:00
resource: {
resource,
2021-01-27 08:45:18 +03:00
'app-name': association['app-name'],
},
metadata: {...metadata, ...newMetadata }
2021-01-27 08:45:18 +03:00
}
});
}