UNPKG

@imbricate/core

Version:

Imbricate Core, Notebook for Engineers

89 lines (88 loc) 3.27 kB
"use strict"; /** * @namespace Document_Property * @description Triage Base */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ImbricateDocumentPropertyTriageBase = void 0; const type_1 = require("../../property/type"); // IMBRICATE_PROPERTY_TYPE SWITCH class ImbricateDocumentPropertyTriageBase { constructor() { this._triageFunctionsByKey = new Map(); this._triageFunctionsByType = new Map(); } /** * Set triage function for property key, * This action will override document value based triage functions * * @param propertyKey property key * @param triageFunction triage function * @returns triage manager */ forPropertyKey(propertyKey, triageFunction) { this._triageFunctionsByKey.set(propertyKey, triageFunction); return this; } forBinary(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.BINARY, triageFunction); return this; } forBoolean(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN, triageFunction); return this; } forString(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.STRING, triageFunction); return this; } forNumber(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.NUMBER, triageFunction); return this; } forMarkdown(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN, triageFunction); return this; } forJson(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.JSON, triageFunction); return this; } forImbriscript(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, triageFunction); return this; } forDate(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.DATE, triageFunction); return this; } forLabel(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.LABEL, triageFunction); return this; } forReference(triageFunction) { this._triageFunctionsByType.set(type_1.IMBRICATE_PROPERTY_TYPE.REFERENCE, triageFunction); return this; } _collect(properties) { const keys = Object.keys(properties); const result = new Map(); for (const key of keys) { const property = properties[key]; const triageFunction = this._triageFunctionsByKey.get(key); if (typeof triageFunction === "function") { const value = triageFunction(key, property); result.set(key, value); continue; } const typeFunction = this._triageFunctionsByType.get(property.propertyType); if (typeof typeFunction === "function") { const value = typeFunction(key, property); result.set(key, value); continue; } } return result; } } exports.ImbricateDocumentPropertyTriageBase = ImbricateDocumentPropertyTriageBase;