UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

74 lines 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FirestoreModelUriConverter = void 0; const firestore_model_field_value_converter_1 = require("../firestore_model_field_value_converter"); const utils_1 = require("../../utils"); /** * FirestoreConverter for [ModelUri]. * * [ModelUri]用のFirestoreConverter。 */ class FirestoreModelUriConverter extends firestore_model_field_value_converter_1.FirestoreModelFieldValueConverter { /** * FirestoreConverter for [ModelUri]. * * [ModelUri]用のFirestoreConverter。 */ constructor() { super(); this.type = "ModelUri"; } convertFrom(key, value, original) { var _a, _b, _c, _d, _e, _f; if (typeof value === "string") { const targetKey = `#${key}`; const targetMap = (_a = original[targetKey]) !== null && _a !== void 0 ? _a : {}; const type = (_b = targetMap["@type"]) !== null && _b !== void 0 ? _b : ""; if (type == this.type) { return { [key]: String(value), }; } } else if (Array.isArray(value)) { const targetKey = `#${key}`; const targetList = (_c = original[targetKey]) !== null && _c !== void 0 ? _c : []; if (targetList != null && targetList.length > 0 && targetList.every((e) => e["@type"] === this.type)) { const res = []; for (const tmp of value) { res.push(String(tmp)); } if (res.length > 0) { return { [key]: res, }; } } } else if ((0, utils_1.isDynamicMap)(value)) { const targetKey = `#${key}`; const targetMap = (_d = original[targetKey]) !== null && _d !== void 0 ? _d : {}; targetMap; if (targetMap != null) { const res = {}; for (const key in value) { const val = value[key]; const mapVal = (_e = targetMap[key]) !== null && _e !== void 0 ? _e : {}; const type = (_f = mapVal["@type"]) !== null && _f !== void 0 ? _f : ""; if (type != this.type) { continue; } res[key] = String(val); } if (Object.keys(res).length > 0) { return { [key]: res, }; } } } return null; } } exports.FirestoreModelUriConverter = FirestoreModelUriConverter; //# sourceMappingURL=firestore_model_uri_converter.js.map