27391954e7aed2a38577043791f14739.json
9.63 KB
{"ast":null,"code":"var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.reload=reload;exports.reloadFromCache=reloadFromCache;exports.checkForUpdateAsync=checkForUpdateAsync;exports.fetchUpdateAsync=fetchUpdateAsync;exports.clearUpdateCacheExperimentalAsync=clearUpdateCacheExperimentalAsync;exports.addListener=addListener;exports.EventType=void 0;var _regenerator=_interopRequireDefault(require(\"@babel/runtime/regenerator\"));var _core=require(\"@unimodules/core\");var _fbemitter=require(\"fbemitter\");var _ExponentUpdates=_interopRequireDefault(require(\"./ExponentUpdates\"));function reload(){return _regenerator.default.async(function reload$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return _regenerator.default.awrap(_ExponentUpdates.default.reload());case 2:case\"end\":return _context.stop();}}});}function reloadFromCache(){return _regenerator.default.async(function reloadFromCache$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.next=2;return _regenerator.default.awrap(_ExponentUpdates.default.reloadFromCache());case 2:case\"end\":return _context2.stop();}}});}function checkForUpdateAsync(){var result;return _regenerator.default.async(function checkForUpdateAsync$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:if(_ExponentUpdates.default.checkForUpdateAsync){_context3.next=2;break;}throw new _core.UnavailabilityError('Updates','checkForUpdateAsync');case 2:_context3.next=4;return _regenerator.default.awrap(_ExponentUpdates.default.checkForUpdateAsync());case 4:result=_context3.sent;if(result){_context3.next=7;break;}return _context3.abrupt(\"return\",{isAvailable:false});case 7:return _context3.abrupt(\"return\",{isAvailable:true,manifest:typeof result==='string'?JSON.parse(result):result});case 8:case\"end\":return _context3.stop();}}});}function fetchUpdateAsync(){var _ref,eventListener,subscription,result,_args4=arguments;return _regenerator.default.async(function fetchUpdateAsync$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:_ref=_args4.length>0&&_args4[0]!==undefined?_args4[0]:{},eventListener=_ref.eventListener;if(_ExponentUpdates.default.fetchUpdateAsync){_context4.next=3;break;}throw new _core.UnavailabilityError('Updates','fetchUpdateAsync');case 3:if(eventListener&&typeof eventListener==='function'){subscription=addListener(eventListener);}_context4.prev=4;_context4.next=7;return _regenerator.default.awrap(_ExponentUpdates.default.fetchUpdateAsync());case 7:result=_context4.sent;case 8:_context4.prev=8;subscription&&subscription.remove();return _context4.finish(8);case 11:if(result){_context4.next=13;break;}return _context4.abrupt(\"return\",{isNew:false});case 13:return _context4.abrupt(\"return\",{isNew:true,manifest:typeof result==='string'?JSON.parse(result):result});case 14:case\"end\":return _context4.stop();}}},null,null,[[4,,8,11]]);}function clearUpdateCacheExperimentalAsync(abiVersion){return _regenerator.default.async(function clearUpdateCacheExperimentalAsync$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:if(_ExponentUpdates.default.clearUpdateCacheAsync){_context5.next=2;break;}throw new _core.UnavailabilityError('Updates','clearUpdateCacheAsync');case 2:return _context5.abrupt(\"return\",_ExponentUpdates.default.clearUpdateCacheAsync(abiVersion));case 3:case\"end\":return _context5.stop();}}});}var _emitter;function _getEmitter(){if(!_emitter){_emitter=new _fbemitter.EventEmitter();_core.RCTDeviceEventEmitter.addListener('Exponent.nativeUpdatesEvent',_emitEvent);}return _emitter;}function _emitEvent(params){var newParams=params;if(typeof params==='string'){newParams=JSON.parse(params);}if(newParams.manifestString){newParams.manifest=JSON.parse(newParams.manifestString);delete newParams.manifestString;}if(!_emitter){throw new Error(\"EventEmitter must be initialized to use from its listener\");}_emitter.emit('Exponent.updatesEvent',newParams);}function addListener(listener){var emitter=_getEmitter();return emitter.addListener('Exponent.updatesEvent',listener);}var EventType={DOWNLOAD_STARTED:'downloadStart',DOWNLOAD_PROGRESS:'downloadProgress',DOWNLOAD_FINISHED:'downloadFinished',NO_UPDATE_AVAILABLE:'noUpdateAvailable',ERROR:'error'};exports.EventType=EventType;","map":{"version":3,"sources":["../../src/Updates/Updates.ts"],"names":[],"mappings":"wfAAA,sCAEA,oCAEA,0E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AAI,CAAC,QAAL,CAAe,CACb,QAAQ,CAAG,GAAI,wBAAJ,EAAX,CACA,4BAAsB,WAAtB,CAAkC,6BAAlC,CAAiE,UAAjE,EACD,CACD,MAAO,CAAA,QAAP,CACD,CAED,QAAS,CAAA,UAAT,CAAoB,MAApB,CAA0B,CACxB,GAAI,CAAA,SAAS,CAAG,MAAhB,CACA,GAAI,MAAO,CAAA,MAAP,GAAkB,QAAtB,CAAgC,CAC9B,SAAS,CAAG,IAAI,CAAC,KAAL,CAAW,MAAX,CAAZ,CACD,CACD,GAAI,SAAS,CAAC,cAAd,CAA8B,CAC5B,SAAS,CAAC,QAAV,CAAqB,IAAI,CAAC,KAAL,CAAW,SAAS,CAAC,cAArB,CAArB,CACA,MAAO,CAAA,SAAS,CAAC,cAAjB,CACD,CAED,GAAI,CAAC,QAAL,CAAe,CACb,KAAM,IAAI,CAAA,KAAJ,6DAAN,CACD,CACD,QAAQ,CAAC,IAAT,CAAc,uBAAd,CAAuC,SAAvC,EACD,CAEK,QAAU,CAAA,WAAV,CAAsB,QAAtB,CAAwC,CAC5C,GAAI,CAAA,OAAO,CAAG,WAAW,EAAzB,CACA,MAAO,CAAA,OAAO,CAAC,WAAR,CAAoB,uBAApB,CAA6C,QAA7C,CAAP,CACD,CAEM,GAAM,CAAA,SAAS,CAAG,CACvB,gBAAgB,CAAE,eADK,CAEvB,iBAAiB,CAAE,kBAFI,CAGvB,iBAAiB,CAAE,kBAHI,CAIvB,mBAAmB,CAAE,mBAJE,CAKvB,KAAK,CAAE,OALgB,CAAlB,C","sourcesContent":["import { RCTDeviceEventEmitter, UnavailabilityError } from '@unimodules/core';\nimport Constants from 'expo-constants';\nimport { EventEmitter, EventSubscription } from 'fbemitter';\n\nimport ExponentUpdates from './ExponentUpdates';\n\ntype Manifest = typeof Constants.manifest;\n\ntype UpdateCheckResult = { isAvailable: false } | { isAvailable: true; manifest: Manifest };\n\ntype UpdateFetchResult = { isNew: false } | { isNew: true; manifest: Manifest };\n\ntype UpdateEvent =\n | { type: 'downloadStart' | 'downloadProgress' | 'noUpdateAvailable' }\n | { type: 'downloadFinished'; manifest: Manifest }\n | { type: 'error'; message: string };\n\ntype UpdateEventListener = (event: UpdateEvent) => void;\n\nexport async function reload(): Promise<void> {\n await ExponentUpdates.reload();\n}\n\nexport async function reloadFromCache(): Promise<void> {\n await ExponentUpdates.reloadFromCache();\n}\n\nexport async function checkForUpdateAsync(): Promise<UpdateCheckResult> {\n if (!ExponentUpdates.checkForUpdateAsync) {\n throw new UnavailabilityError('Updates', 'checkForUpdateAsync');\n }\n const result = await ExponentUpdates.checkForUpdateAsync();\n if (!result) {\n return { isAvailable: false };\n }\n\n return {\n isAvailable: true,\n manifest: typeof result === 'string' ? JSON.parse(result) : result,\n };\n}\n\nexport async function fetchUpdateAsync({\n eventListener,\n}: { eventListener?: UpdateEventListener } = {}): Promise<UpdateFetchResult> {\n if (!ExponentUpdates.fetchUpdateAsync) {\n throw new UnavailabilityError('Updates', 'fetchUpdateAsync');\n }\n let subscription;\n let result;\n if (eventListener && typeof eventListener === 'function') {\n subscription = addListener(eventListener);\n }\n try {\n result = await ExponentUpdates.fetchUpdateAsync();\n } finally {\n subscription && subscription.remove();\n }\n\n if (!result) {\n return { isNew: false };\n }\n\n return {\n isNew: true,\n manifest: typeof result === 'string' ? JSON.parse(result) : result,\n };\n}\n\nexport async function clearUpdateCacheExperimentalAsync(abiVersion: string): Promise<void> {\n if (!ExponentUpdates.clearUpdateCacheAsync) {\n throw new UnavailabilityError('Updates', 'clearUpdateCacheAsync');\n }\n return ExponentUpdates.clearUpdateCacheAsync(abiVersion);\n}\n\nlet _emitter: EventEmitter | null;\n\nfunction _getEmitter(): EventEmitter {\n if (!_emitter) {\n _emitter = new EventEmitter();\n RCTDeviceEventEmitter.addListener('Exponent.nativeUpdatesEvent', _emitEvent);\n }\n return _emitter;\n}\n\nfunction _emitEvent(params): void {\n let newParams = params;\n if (typeof params === 'string') {\n newParams = JSON.parse(params);\n }\n if (newParams.manifestString) {\n newParams.manifest = JSON.parse(newParams.manifestString);\n delete newParams.manifestString;\n }\n\n if (!_emitter) {\n throw new Error(`EventEmitter must be initialized to use from its listener`);\n }\n _emitter.emit('Exponent.updatesEvent', newParams);\n}\n\nexport function addListener(listener: Function): EventSubscription {\n let emitter = _getEmitter();\n return emitter.addListener('Exponent.updatesEvent', listener);\n}\n\nexport const EventType = {\n DOWNLOAD_STARTED: 'downloadStart',\n DOWNLOAD_PROGRESS: 'downloadProgress',\n DOWNLOAD_FINISHED: 'downloadFinished',\n NO_UPDATE_AVAILABLE: 'noUpdateAvailable',\n ERROR: 'error',\n};\n"],"sourceRoot":""},"metadata":{},"sourceType":"script"}