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.cjs.js 18KB

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