No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.esm5.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. import firebase from '@firebase/app-compat';
  2. import { _getChild, uploadBytesResumable, StringFormat, _dataFromString, _UploadTask, _FbsBlob, listAll, list, getMetadata, updateMetadata, getDownloadURL, deleteObject, _invalidRootOperation, _invalidArgument, ref, _Location, connectStorageEmulator, _TaskState, _TaskEvent } from '@firebase/storage';
  3. import { __assign } from 'tslib';
  4. import { Component } from '@firebase/component';
  5. /**
  6. * @license
  7. * Copyright 2020 Google LLC
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. var UploadTaskSnapshotCompat = /** @class */ (function () {
  22. function UploadTaskSnapshotCompat(_delegate, task, ref) {
  23. this._delegate = _delegate;
  24. this.task = task;
  25. this.ref = ref;
  26. }
  27. Object.defineProperty(UploadTaskSnapshotCompat.prototype, "bytesTransferred", {
  28. get: function () {
  29. return this._delegate.bytesTransferred;
  30. },
  31. enumerable: false,
  32. configurable: true
  33. });
  34. Object.defineProperty(UploadTaskSnapshotCompat.prototype, "metadata", {
  35. get: function () {
  36. return this._delegate.metadata;
  37. },
  38. enumerable: false,
  39. configurable: true
  40. });
  41. Object.defineProperty(UploadTaskSnapshotCompat.prototype, "state", {
  42. get: function () {
  43. return this._delegate.state;
  44. },
  45. enumerable: false,
  46. configurable: true
  47. });
  48. Object.defineProperty(UploadTaskSnapshotCompat.prototype, "totalBytes", {
  49. get: function () {
  50. return this._delegate.totalBytes;
  51. },
  52. enumerable: false,
  53. configurable: true
  54. });
  55. return UploadTaskSnapshotCompat;
  56. }());
  57. /**
  58. * @license
  59. * Copyright 2020 Google LLC
  60. *
  61. * Licensed under the Apache License, Version 2.0 (the "License");
  62. * you may not use this file except in compliance with the License.
  63. * You may obtain a copy of the License at
  64. *
  65. * http://www.apache.org/licenses/LICENSE-2.0
  66. *
  67. * Unless required by applicable law or agreed to in writing, software
  68. * distributed under the License is distributed on an "AS IS" BASIS,
  69. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  70. * See the License for the specific language governing permissions and
  71. * limitations under the License.
  72. */
  73. var UploadTaskCompat = /** @class */ (function () {
  74. function UploadTaskCompat(_delegate, _ref) {
  75. this._delegate = _delegate;
  76. this._ref = _ref;
  77. this.cancel = this._delegate.cancel.bind(this._delegate);
  78. this.catch = this._delegate.catch.bind(this._delegate);
  79. this.pause = this._delegate.pause.bind(this._delegate);
  80. this.resume = this._delegate.resume.bind(this._delegate);
  81. }
  82. Object.defineProperty(UploadTaskCompat.prototype, "snapshot", {
  83. get: function () {
  84. return new UploadTaskSnapshotCompat(this._delegate.snapshot, this, this._ref);
  85. },
  86. enumerable: false,
  87. configurable: true
  88. });
  89. UploadTaskCompat.prototype.then = function (onFulfilled, onRejected) {
  90. var _this = this;
  91. return this._delegate.then(function (snapshot) {
  92. if (onFulfilled) {
  93. return onFulfilled(new UploadTaskSnapshotCompat(snapshot, _this, _this._ref));
  94. }
  95. }, onRejected);
  96. };
  97. UploadTaskCompat.prototype.on = function (type, nextOrObserver, error, completed) {
  98. var _this = this;
  99. var wrappedNextOrObserver = undefined;
  100. if (!!nextOrObserver) {
  101. if (typeof nextOrObserver === 'function') {
  102. wrappedNextOrObserver = function (taskSnapshot) {
  103. return nextOrObserver(new UploadTaskSnapshotCompat(taskSnapshot, _this, _this._ref));
  104. };
  105. }
  106. else {
  107. wrappedNextOrObserver = {
  108. next: !!nextOrObserver.next
  109. ? function (taskSnapshot) {
  110. return nextOrObserver.next(new UploadTaskSnapshotCompat(taskSnapshot, _this, _this._ref));
  111. }
  112. : undefined,
  113. complete: nextOrObserver.complete || undefined,
  114. error: nextOrObserver.error || undefined
  115. };
  116. }
  117. }
  118. return this._delegate.on(type, wrappedNextOrObserver, error || undefined, completed || undefined);
  119. };
  120. return UploadTaskCompat;
  121. }());
  122. var ListResultCompat = /** @class */ (function () {
  123. function ListResultCompat(_delegate, _service) {
  124. this._delegate = _delegate;
  125. this._service = _service;
  126. }
  127. Object.defineProperty(ListResultCompat.prototype, "prefixes", {
  128. get: function () {
  129. var _this = this;
  130. return this._delegate.prefixes.map(function (ref) { return new ReferenceCompat(ref, _this._service); });
  131. },
  132. enumerable: false,
  133. configurable: true
  134. });
  135. Object.defineProperty(ListResultCompat.prototype, "items", {
  136. get: function () {
  137. var _this = this;
  138. return this._delegate.items.map(function (ref) { return new ReferenceCompat(ref, _this._service); });
  139. },
  140. enumerable: false,
  141. configurable: true
  142. });
  143. Object.defineProperty(ListResultCompat.prototype, "nextPageToken", {
  144. get: function () {
  145. return this._delegate.nextPageToken || null;
  146. },
  147. enumerable: false,
  148. configurable: true
  149. });
  150. return ListResultCompat;
  151. }());
  152. /**
  153. * @license
  154. * Copyright 2020 Google LLC
  155. *
  156. * Licensed under the Apache License, Version 2.0 (the "License");
  157. * you may not use this file except in compliance with the License.
  158. * You may obtain a copy of the License at
  159. *
  160. * http://www.apache.org/licenses/LICENSE-2.0
  161. *
  162. * Unless required by applicable law or agreed to in writing, software
  163. * distributed under the License is distributed on an "AS IS" BASIS,
  164. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  165. * See the License for the specific language governing permissions and
  166. * limitations under the License.
  167. */
  168. var ReferenceCompat = /** @class */ (function () {
  169. function ReferenceCompat(_delegate, storage) {
  170. this._delegate = _delegate;
  171. this.storage = storage;
  172. }
  173. Object.defineProperty(ReferenceCompat.prototype, "name", {
  174. get: function () {
  175. return this._delegate.name;
  176. },
  177. enumerable: false,
  178. configurable: true
  179. });
  180. Object.defineProperty(ReferenceCompat.prototype, "bucket", {
  181. get: function () {
  182. return this._delegate.bucket;
  183. },
  184. enumerable: false,
  185. configurable: true
  186. });
  187. Object.defineProperty(ReferenceCompat.prototype, "fullPath", {
  188. get: function () {
  189. return this._delegate.fullPath;
  190. },
  191. enumerable: false,
  192. configurable: true
  193. });
  194. ReferenceCompat.prototype.toString = function () {
  195. return this._delegate.toString();
  196. };
  197. /**
  198. * @returns A reference to the object obtained by
  199. * appending childPath, removing any duplicate, beginning, or trailing
  200. * slashes.
  201. */
  202. ReferenceCompat.prototype.child = function (childPath) {
  203. var reference = _getChild(this._delegate, childPath);
  204. return new ReferenceCompat(reference, this.storage);
  205. };
  206. Object.defineProperty(ReferenceCompat.prototype, "root", {
  207. get: function () {
  208. return new ReferenceCompat(this._delegate.root, this.storage);
  209. },
  210. enumerable: false,
  211. configurable: true
  212. });
  213. Object.defineProperty(ReferenceCompat.prototype, "parent", {
  214. /**
  215. * @returns A reference to the parent of the
  216. * current object, or null if the current object is the root.
  217. */
  218. get: function () {
  219. var reference = this._delegate.parent;
  220. if (reference == null) {
  221. return null;
  222. }
  223. return new ReferenceCompat(reference, this.storage);
  224. },
  225. enumerable: false,
  226. configurable: true
  227. });
  228. /**
  229. * Uploads a blob to this object's location.
  230. * @param data - The blob to upload.
  231. * @returns An UploadTask that lets you control and
  232. * observe the upload.
  233. */
  234. ReferenceCompat.prototype.put = function (data, metadata) {
  235. this._throwIfRoot('put');
  236. return new UploadTaskCompat(uploadBytesResumable(this._delegate, data, metadata), this);
  237. };
  238. /**
  239. * Uploads a string to this object's location.
  240. * @param value - The string to upload.
  241. * @param format - The format of the string to upload.
  242. * @returns An UploadTask that lets you control and
  243. * observe the upload.
  244. */
  245. ReferenceCompat.prototype.putString = function (value, format, metadata) {
  246. if (format === void 0) { format = StringFormat.RAW; }
  247. this._throwIfRoot('putString');
  248. var data = _dataFromString(format, value);
  249. var metadataClone = __assign({}, metadata);
  250. if (metadataClone['contentType'] == null && data.contentType != null) {
  251. metadataClone['contentType'] = data.contentType;
  252. }
  253. return new UploadTaskCompat(new _UploadTask(this._delegate, new _FbsBlob(data.data, true), metadataClone), this);
  254. };
  255. /**
  256. * List all items (files) and prefixes (folders) under this storage reference.
  257. *
  258. * This is a helper method for calling list() repeatedly until there are
  259. * no more results. The default pagination size is 1000.
  260. *
  261. * Note: The results may not be consistent if objects are changed while this
  262. * operation is running.
  263. *
  264. * Warning: listAll may potentially consume too many resources if there are
  265. * too many results.
  266. *
  267. * @returns A Promise that resolves with all the items and prefixes under
  268. * the current storage reference. `prefixes` contains references to
  269. * sub-directories and `items` contains references to objects in this
  270. * folder. `nextPageToken` is never returned.
  271. */
  272. ReferenceCompat.prototype.listAll = function () {
  273. var _this = this;
  274. return listAll(this._delegate).then(function (r) { return new ListResultCompat(r, _this.storage); });
  275. };
  276. /**
  277. * List items (files) and prefixes (folders) under this storage reference.
  278. *
  279. * List API is only available for Firebase Rules Version 2.
  280. *
  281. * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
  282. * delimited folder structure. Refer to GCS's List API if you want to learn more.
  283. *
  284. * To adhere to Firebase Rules's Semantics, Firebase Storage does not
  285. * support objects whose paths end with "/" or contain two consecutive
  286. * "/"s. Firebase Storage List API will filter these unsupported objects.
  287. * list() may fail if there are too many unsupported objects in the bucket.
  288. *
  289. * @param options - See ListOptions for details.
  290. * @returns A Promise that resolves with the items and prefixes.
  291. * `prefixes` contains references to sub-folders and `items`
  292. * contains references to objects in this folder. `nextPageToken`
  293. * can be used to get the rest of the results.
  294. */
  295. ReferenceCompat.prototype.list = function (options) {
  296. var _this = this;
  297. return list(this._delegate, options || undefined).then(function (r) { return new ListResultCompat(r, _this.storage); });
  298. };
  299. /**
  300. * A `Promise` that resolves with the metadata for this object. If this
  301. * object doesn't exist or metadata cannot be retreived, the promise is
  302. * rejected.
  303. */
  304. ReferenceCompat.prototype.getMetadata = function () {
  305. return getMetadata(this._delegate);
  306. };
  307. /**
  308. * Updates the metadata for this object.
  309. * @param metadata - The new metadata for the object.
  310. * Only values that have been explicitly set will be changed. Explicitly
  311. * setting a value to null will remove the metadata.
  312. * @returns A `Promise` that resolves
  313. * with the new metadata for this object.
  314. * @see firebaseStorage.Reference.prototype.getMetadata
  315. */
  316. ReferenceCompat.prototype.updateMetadata = function (metadata) {
  317. return updateMetadata(this._delegate, metadata);
  318. };
  319. /**
  320. * @returns A `Promise` that resolves with the download
  321. * URL for this object.
  322. */
  323. ReferenceCompat.prototype.getDownloadURL = function () {
  324. return getDownloadURL(this._delegate);
  325. };
  326. /**
  327. * Deletes the object at this location.
  328. * @returns A `Promise` that resolves if the deletion succeeds.
  329. */
  330. ReferenceCompat.prototype.delete = function () {
  331. this._throwIfRoot('delete');
  332. return deleteObject(this._delegate);
  333. };
  334. ReferenceCompat.prototype._throwIfRoot = function (name) {
  335. if (this._delegate._location.path === '') {
  336. throw _invalidRootOperation(name);
  337. }
  338. };
  339. return ReferenceCompat;
  340. }());
  341. /**
  342. * @license
  343. * Copyright 2020 Google LLC
  344. *
  345. * Licensed under the Apache License, Version 2.0 (the "License");
  346. * you may not use this file except in compliance with the License.
  347. * You may obtain a copy of the License at
  348. *
  349. * http://www.apache.org/licenses/LICENSE-2.0
  350. *
  351. * Unless required by applicable law or agreed to in writing, software
  352. * distributed under the License is distributed on an "AS IS" BASIS,
  353. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  354. * See the License for the specific language governing permissions and
  355. * limitations under the License.
  356. */
  357. /**
  358. * A service that provides firebaseStorage.Reference instances.
  359. * @param opt_url gs:// url to a custom Storage Bucket
  360. */
  361. var StorageServiceCompat = /** @class */ (function () {
  362. function StorageServiceCompat(app, _delegate) {
  363. this.app = app;
  364. this._delegate = _delegate;
  365. }
  366. Object.defineProperty(StorageServiceCompat.prototype, "maxOperationRetryTime", {
  367. get: function () {
  368. return this._delegate.maxOperationRetryTime;
  369. },
  370. enumerable: false,
  371. configurable: true
  372. });
  373. Object.defineProperty(StorageServiceCompat.prototype, "maxUploadRetryTime", {
  374. get: function () {
  375. return this._delegate.maxUploadRetryTime;
  376. },
  377. enumerable: false,
  378. configurable: true
  379. });
  380. /**
  381. * Returns a firebaseStorage.Reference for the given path in the default
  382. * bucket.
  383. */
  384. StorageServiceCompat.prototype.ref = function (path) {
  385. if (isUrl(path)) {
  386. throw _invalidArgument('ref() expected a child path but got a URL, use refFromURL instead.');
  387. }
  388. return new ReferenceCompat(ref(this._delegate, path), this);
  389. };
  390. /**
  391. * Returns a firebaseStorage.Reference object for the given absolute URL,
  392. * which must be a gs:// or http[s]:// URL.
  393. */
  394. StorageServiceCompat.prototype.refFromURL = function (url) {
  395. if (!isUrl(url)) {
  396. throw _invalidArgument('refFromURL() expected a full URL but got a child path, use ref() instead.');
  397. }
  398. try {
  399. _Location.makeFromUrl(url, this._delegate.host);
  400. }
  401. catch (e) {
  402. throw _invalidArgument('refFromUrl() expected a valid full URL but got an invalid one.');
  403. }
  404. return new ReferenceCompat(ref(this._delegate, url), this);
  405. };
  406. StorageServiceCompat.prototype.setMaxUploadRetryTime = function (time) {
  407. this._delegate.maxUploadRetryTime = time;
  408. };
  409. StorageServiceCompat.prototype.setMaxOperationRetryTime = function (time) {
  410. this._delegate.maxOperationRetryTime = time;
  411. };
  412. StorageServiceCompat.prototype.useEmulator = function (host, port, options) {
  413. if (options === void 0) { options = {}; }
  414. connectStorageEmulator(this._delegate, host, port, options);
  415. };
  416. return StorageServiceCompat;
  417. }());
  418. function isUrl(path) {
  419. return /^[A-Za-z]+:\/\//.test(path);
  420. }
  421. var name = "@firebase/storage-compat";
  422. var version = "0.2.1";
  423. /**
  424. * @license
  425. * Copyright 2020 Google LLC
  426. *
  427. * Licensed under the Apache License, Version 2.0 (the "License");
  428. * you may not use this file except in compliance with the License.
  429. * You may obtain a copy of the License at
  430. *
  431. * http://www.apache.org/licenses/LICENSE-2.0
  432. *
  433. * Unless required by applicable law or agreed to in writing, software
  434. * distributed under the License is distributed on an "AS IS" BASIS,
  435. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  436. * See the License for the specific language governing permissions and
  437. * limitations under the License.
  438. */
  439. /**
  440. * Type constant for Firebase Storage.
  441. */
  442. var STORAGE_TYPE = 'storage-compat';
  443. function factory(container, _a) {
  444. var url = _a.instanceIdentifier;
  445. // Dependencies
  446. var app = container.getProvider('app-compat').getImmediate();
  447. var storageExp = container
  448. .getProvider('storage')
  449. .getImmediate({ identifier: url });
  450. var storageServiceCompat = new StorageServiceCompat(app, storageExp);
  451. return storageServiceCompat;
  452. }
  453. function registerStorage(instance) {
  454. var namespaceExports = {
  455. // no-inline
  456. TaskState: _TaskState,
  457. TaskEvent: _TaskEvent,
  458. StringFormat: StringFormat,
  459. Storage: StorageServiceCompat,
  460. Reference: ReferenceCompat
  461. };
  462. instance.INTERNAL.registerComponent(new Component(STORAGE_TYPE, factory, "PUBLIC" /* ComponentType.PUBLIC */)
  463. .setServiceProps(namespaceExports)
  464. .setMultipleInstances(true));
  465. instance.registerVersion(name, version);
  466. }
  467. registerStorage(firebase);
  468. export { registerStorage };
  469. //# sourceMappingURL=index.esm5.js.map