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Aa,CAAC,KAAK,EAAE,CAAA;QAC1C,IAAI,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAAE,OAAM;QAElD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;gBACtC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,QAAuB,EAAE,EAAE,CACjD,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAChC,CAAA;YACL,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAA;YAC7C,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,MAAM,CAAC,YAAY,CAAC;gBACpB,IAAI,CAAC,wBAAwB,CACzB,MAAM,CAAC,YAAY,CAAC,EACpB,aAAa,CAChB,CAAA;QACT,CAAC;IACL,CAAC;CACJ","file":"EntityListenerMetadata.js","sourcesContent":["import { EventListenerType } from \"./types/EventListenerTypes\"\nimport { EntityListenerMetadataArgs } from \"../metadata-args/EntityListenerMetadataArgs\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { EntityMetadata } from \"./EntityMetadata\"\nimport { EmbeddedMetadata } from \"./EmbeddedMetadata\"\n\n/**\n * This metadata contains all information about entity's listeners.\n */\nexport class EntityListenerMetadata {\n // ---------------------------------------------------------------------\n // Properties\n // ---------------------------------------------------------------------\n\n /**\n * Entity metadata of the listener.\n */\n entityMetadata: EntityMetadata\n\n /**\n * Embedded metadata of the listener, in the case if listener is in embedded.\n */\n embeddedMetadata?: EmbeddedMetadata\n\n /**\n * Target class to which metadata is applied.\n * This can be different then entityMetadata.target in the case if listener is in the embedded.\n */\n target: Function | string\n\n /**\n * Target's property name to which this metadata is applied.\n */\n propertyName: string\n\n /**\n * The type of the listener.\n */\n type: EventListenerType\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(options: {\n entityMetadata: EntityMetadata\n embeddedMetadata?: EmbeddedMetadata\n args: EntityListenerMetadataArgs\n }) {\n this.entityMetadata = options.entityMetadata\n this.embeddedMetadata = options.embeddedMetadata\n this.target = options.args.target\n this.propertyName = options.args.propertyName\n this.type = options.args.type\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Checks if entity listener is allowed to be executed on the given entity.\n */\n isAllowed(entity: ObjectLiteral) {\n // todo: create in entity metadata method like isInherited?\n return (\n this.entityMetadata.target === entity.constructor || // todo: .constructor won't work for entity schemas, but there are no entity listeners in schemas since there are no objects, right?\n (typeof this.entityMetadata.target === \"function\" &&\n entity.constructor.prototype instanceof\n this.entityMetadata.target)\n ) // todo: also need to implement entity schema inheritance\n }\n\n /**\n * Executes listener method of the given entity.\n */\n execute(entity: ObjectLiteral) {\n if (!this.embeddedMetadata) return entity[this.propertyName]()\n\n this.callEntityEmbeddedMethod(\n entity,\n this.embeddedMetadata.propertyPath.split(\".\"),\n )\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Calls embedded entity listener method no matter how nested it is.\n */\n protected callEntityEmbeddedMethod(\n entity: ObjectLiteral,\n propertyPaths: string[],\n ): void {\n const propertyPath = propertyPaths.shift()\n if (!propertyPath || !entity[propertyPath]) return\n\n if (propertyPaths.length === 0) {\n if (Array.isArray(entity[propertyPath])) {\n entity[propertyPath].map((embedded: ObjectLiteral) =>\n embedded[this.propertyName](),\n )\n } else {\n entity[propertyPath][this.propertyName]()\n }\n } else {\n if (entity[propertyPath])\n this.callEntityEmbeddedMethod(\n entity[propertyPath],\n propertyPaths,\n )\n }\n }\n}\n"],"sourceRoot":".."}