@kit-data-manager/pid-component
Version:
The PID-Component is a web component that can be used to evaluate and display FAIR Digital Objects, PIDs, ORCiDs, and possibly other identifiers in a user-friendly way. It is easily extensible to support other identifier types.
76 lines (75 loc) • 2.63 kB
JavaScript
/*!
*
* Copyright 2024 Karlsruhe Institute of Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { PIDDataType } from "./PIDDataType";
import { PID } from "./PID";
export class PIDRecord {
constructor(pid, values) {
this._values = [];
this._pid = pid;
this._values = values;
}
get pid() {
return this._pid;
}
get values() {
return this._values;
}
static fromJSON(serialized) {
const data = JSON.parse(serialized);
const values = data.values.map(value => {
const parsed = JSON.parse(value);
const parsedType = JSON.parse(parsed.type);
let type;
if (parsedType.pidDataType !== undefined) {
type = PIDDataType.fromJSON(parsedType.pidDataType);
}
else if (parsedType.pid !== undefined) {
type = PID.fromJSON(parsedType.pid);
}
else {
type = parsedType.string;
}
const data = JSON.parse(parsed.data);
return {
index: parsed.index,
type: type,
data: data,
ttl: parsed.ttl,
timestamp: parsed.timestamp,
};
});
return new PIDRecord(PID.fromJSON(data.pid), values);
}
toObject() {
return {
pid: JSON.stringify(this._pid.toObject()),
values: this._values.map(value => JSON.stringify({
index: value.index,
type: JSON.stringify({
pid: value.type instanceof PID ? JSON.stringify(value.type.toObject()) : undefined,
pidDataType: value.type instanceof PIDDataType ? JSON.stringify(value.type.toObject()) : undefined,
string: typeof value.type == 'string' ? value.type : undefined,
}),
data: JSON.stringify(value.data),
ttl: value.ttl,
timestamp: value.timestamp,
})),
};
}
}
//# sourceMappingURL=PIDRecord.js.map