2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-04-08 17:03:18 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { setProperties } from '@ember/object';
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class LocalStorageService extends Service {
|
|
|
|
@service('settings')
|
|
|
|
settings;
|
|
|
|
|
|
|
|
prepare(sink, data, instance = {}) {
|
2020-05-01 08:49:33 +00:00
|
|
|
if (data === null || data === '') {
|
2020-04-08 17:03:18 +00:00
|
|
|
return instance;
|
|
|
|
}
|
2020-05-01 08:49:33 +00:00
|
|
|
return setProperties(instance, data);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
persist(sink, instance) {
|
2020-04-08 17:03:18 +00:00
|
|
|
const slug = sink.split(':').pop();
|
|
|
|
const repo = this.settings;
|
|
|
|
return repo.persist({
|
|
|
|
[slug]: instance,
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remove(sink, instance) {
|
2020-04-08 17:03:18 +00:00
|
|
|
const slug = sink.split(':').pop();
|
|
|
|
const repo = this.settings;
|
|
|
|
return repo.delete(slug);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|