@mathrunet/masamune
Version:
Manages packages for the server portion (NodeJS) of the Masamune framework.
119 lines • 5.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FirestoreModelServerCommandBaseConverter = exports.ModelServerCommandBaseConverter = void 0;
const model_field_value_converter_1 = require("../model_field_value_converter");
const model_field_value_1 = require("../model_field_value");
const default_model_field_value_converter_1 = require("../default_model_field_value_converter");
/**
* ModelServerCommandBase ModelFieldValueConverter.
*
* ModelServerCommandBase用のModelFieldValueConverter。
*/
class ModelServerCommandBaseConverter extends model_field_value_converter_1.ModelFieldValueConverter {
/**
* ModelServerCommandBase ModelFieldValueConverter.
*
* ModelServerCommandBase用のModelFieldValueConverter。
*/
constructor() {
super();
}
type = "ModelServerCommandBase";
convertFrom(key, value, original) {
if (value !== null && typeof value === "object" && "@type" in value && value["@type"] === this.type) {
const command = value["@command"] ?? "";
const publicParameters = value["@public"] ?? {};
const privateParameters = value["@private"] ?? {};
const publicConverted = default_model_field_value_converter_1.ModelFieldValueConverterUtils.convertFrom({ data: publicParameters });
const privateConverted = default_model_field_value_converter_1.ModelFieldValueConverterUtils.convertFrom({ data: privateParameters });
return {
[key]: new model_field_value_1.ModelServerCommandBase({
command: command,
publicParameters: publicConverted,
privateParameters: privateConverted,
source: "server",
}),
};
}
return null;
}
convertTo(key, value, original) {
if (value instanceof model_field_value_1.ModelServerCommandBase) {
const publicParameters = default_model_field_value_converter_1.ModelFieldValueConverterUtils.convertTo({ data: value["@public"] });
const privateParameters = default_model_field_value_converter_1.ModelFieldValueConverterUtils.convertTo({ data: value["@private"] });
return {
[key]: {
"@type": this.type,
"@command": value["@command"],
"@public": publicParameters,
"@private": privateParameters,
"@source": value["@source"],
},
};
}
return null;
}
}
exports.ModelServerCommandBaseConverter = ModelServerCommandBaseConverter;
/**
* FirestoreConverter for [ModelServerCommandBase].
*
* [ModelServerCommandBase]用のFirestoreConverter。
*/
class FirestoreModelServerCommandBaseConverter extends model_field_value_converter_1.FirestoreModelFieldValueConverter {
/**
* FirestoreConverter for [ModelServerCommandBase].
*
* [ModelServerCommandBase]用のFirestoreConverter。
*/
constructor() {
super();
}
type = "ModelServerCommandBase";
convertFrom(key, value, original, firestoreInstance) {
if (typeof value === "string") {
const targetKey = `#${key}`;
const targetMap = original[targetKey] ?? {};
const publicParameters = targetMap["@public"] ?? {};
const privateParameters = targetMap["@private"] ?? {};
const type = targetMap["@type"] ?? "";
if (type == this.type) {
return {
[key]: {
"@command": value,
"@public": publicParameters,
"@private": privateParameters,
...this.header(),
},
[targetKey]: null,
};
}
}
return null;
}
convertTo(key, value, _original, firestoreInstance) {
if (value != null && typeof value === "object" && "@type" in value) {
const type = value["@type"] ?? "";
if (type === this.type) {
const command = value["@command"] ?? "";
const publicParameters = value["@public"] ?? {};
const privateParameters = value["@private"] ?? {};
const targetKey = `#${key}`;
return {
...publicParameters,
[targetKey]: {
"@type": this.type,
"@command": command,
"@public": publicParameters,
"@private": privateParameters,
"@target": key,
},
[key]: command,
};
}
}
return null;
}
}
exports.FirestoreModelServerCommandBaseConverter = FirestoreModelServerCommandBaseConverter;
//# sourceMappingURL=model_server_command_base_converter.js.map