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,
|
2021-02-17 05:23:49 +03:00
|
|
|
resource: string,
|
|
|
|
group: string,
|
|
|
|
metadata: Metadata,
|
2021-01-27 08:45:18 +03:00
|
|
|
): Poke<MetadataUpdateAdd> => {
|
|
|
|
return action({
|
|
|
|
add: {
|
2021-02-17 05:23:49 +03:00
|
|
|
group,
|
2021-01-27 08:45:18 +03:00
|
|
|
resource: {
|
2021-02-17 05:23:49 +03:00
|
|
|
resource,
|
2021-01-27 08:45:18 +03:00
|
|
|
'app-name': appName
|
|
|
|
},
|
2021-02-17 05:23:49 +03:00
|
|
|
metadata
|
2021-01-27 08:45:18 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export const update = (
|
|
|
|
association: Association,
|
|
|
|
newMetadata: Partial<Metadata>
|
2021-02-17 05:23:49 +03:00
|
|
|
): Poke<MetadataUpdateAdd> => {
|
|
|
|
const { resource, metadata, group } = association;
|
2021-01-27 08:45:18 +03:00
|
|
|
return action({
|
|
|
|
add: {
|
2021-02-17 05:23:49 +03:00
|
|
|
group,
|
2021-01-27 08:45:18 +03:00
|
|
|
resource: {
|
2021-02-17 05:23:49 +03:00
|
|
|
resource,
|
2021-01-27 08:45:18 +03:00
|
|
|
'app-name': association['app-name'],
|
|
|
|
},
|
2021-02-17 05:23:49 +03:00
|
|
|
metadata: {...metadata, ...newMetadata }
|
2021-01-27 08:45:18 +03:00
|
|
|
}
|
|
|
|
});
|
2021-02-17 05:23:49 +03:00
|
|
|
}
|