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,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAE1C,CAAC;AAED,SAAS,UAAU,CAAC,UAAkB,EAAE,GAAG,KAAkB;IAC3D,IAAI,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;KAC9B;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC1B,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YACjD,IAAI,QAAQ,GAAG,UAAU,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,CAAA;YACjD,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE;gBACzB,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;aACtB;SACF;KACF;IACD,OAAO,aAAa,CAAA;AACtB,CAAC","file":"","sourceRoot":"/","sourcesContent":["\n\n/**\n * Type information\n * Type instance provide a isInstanceOf function for the interface type T\n */\ninterface Type<T> {\n id: string;\n assignableTypes: string;\n superTypes?: Type<any>[]\n isInstanceOf(obj: any): obj is T\n}\n\n/**\n * All Types needs to use Nominal Type System must implements this interface\n * Any instance of this type \"T\" can be assigned to types which id is in __assignableTypes, separated by '|'\n */\ninterface NominalTypeSupported {\n __assignableTypes: string\n}\n\nconst Type = {\n registry: new Map<string, Type<any>>(),\n /**\n * \n * @param typeId must unique in app\n */\n declare<T extends NominalTypeSupported>(typeId: string, ...superTypes: Type<any>[]): Type<T> {\n if (this.registry.has(typeId)) {\n throw Error(\"The type named '\" + typeId + \"' had been registered already. Check the conflict of the name.\")\n }\n\n\n let assignableTypes = calTypeId(typeId, ...superTypes)\n let typeObj = {\n id: typeId,\n superTypes: superTypes,\n assignableTypes: assignableTypes,\n\n /**\n * test if obj is a T instance.\n * @param obj \n */\n isInstanceOf(obj: any): obj is T {\n let objTypeId = (obj as T).__assignableTypes\n console.log(\"isInstanceOf: objTypeId=\" + objTypeId)\n\n // undefined false\n if (objTypeId === undefined) return false\n // single type\n console.log(\"isInstanceOf: __id=\" + this.id)\n if (objTypeId === this.id) return true\n\n // union types\n let objTypeIds = objTypeId.split(\"|\")\n for (const i in objTypeIds) {\n let id = objTypeIds[i]\n console.log(\"isInstanceOf: id=\" + id)\n if (id === this.id) return true\n }\n\n return false\n }\n }\n\n this.registry.set(typeId, typeObj)\n\n console.log(\"type=\" + typeId + \"Type\")\n console.log(\"assignableTypes=\" + assignableTypes)\n console.log(\"typeId=\" + typeId)\n return typeObj\n },\n\n getType<T extends NominalTypeSupported>(typeId: string): Type<T>{\n if (this.registry.has(typeId)) return this.registry.get(typeId)\n throw new Error(\"Type [\" + typeId + \"] is not found!\")\n },\n\n isInstanceOf<T>(typeId: string, obj: any): boolean{\n if (!this.registry.has(typeId)) return false;\n let typeObj = this.registry.get(typeId) as Type<T>\n return typeObj.isInstanceOf(obj)\n }\n\n\n}\n\n/**\n * \n * @param types \n * @returns \n */\nfunction calTypeId(selfTypeId: string, ...types: Type<any>[]): string {\n let idSet = _calTypeId(selfTypeId, ...types)\n let idStr = \"\"\n idSet.forEach(id => {\n idStr += id + \"|\"\n })\n return idStr.substr(0, idStr.length - 1)\n\n}\n\nfunction _calTypeId(selfTypeId: string, ...types: Type<any>[]): Set<string> {\n let resultTypeIds = new Set<string>();\n if (selfTypeId.length > 0) {\n resultTypeIds.add(selfTypeId)\n }\n\n for (const type of types) {\n resultTypeIds.add(type.id)\n if (type.superTypes && type.superTypes.length > 0) {\n let superIds = _calTypeId(\"\", ...type.superTypes)\n for (const id of superIds) {\n resultTypeIds.add(id)\n }\n }\n }\n return resultTypeIds\n}\n\n\nexport { Type, NominalTypeSupported }\n\n"]}