123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- 'use strict';
-
- Object.defineProperty(exports, '__esModule', { value: true });
-
- var firebase = require('@firebase/app-compat');
- var storage = require('@firebase/storage');
- var tslib = require('tslib');
- var component = require('@firebase/component');
-
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
-
- var firebase__default = _interopDefaultLegacy(firebase);
-
-
- var UploadTaskSnapshotCompat = (function () {
- function UploadTaskSnapshotCompat(_delegate, task, ref) {
- this._delegate = _delegate;
- this.task = task;
- this.ref = ref;
- }
- Object.defineProperty(UploadTaskSnapshotCompat.prototype, "bytesTransferred", {
- get: function () {
- return this._delegate.bytesTransferred;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(UploadTaskSnapshotCompat.prototype, "metadata", {
- get: function () {
- return this._delegate.metadata;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(UploadTaskSnapshotCompat.prototype, "state", {
- get: function () {
- return this._delegate.state;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(UploadTaskSnapshotCompat.prototype, "totalBytes", {
- get: function () {
- return this._delegate.totalBytes;
- },
- enumerable: false,
- configurable: true
- });
- return UploadTaskSnapshotCompat;
- }());
-
-
- var UploadTaskCompat = (function () {
- function UploadTaskCompat(_delegate, _ref) {
- this._delegate = _delegate;
- this._ref = _ref;
- this.cancel = this._delegate.cancel.bind(this._delegate);
- this.catch = this._delegate.catch.bind(this._delegate);
- this.pause = this._delegate.pause.bind(this._delegate);
- this.resume = this._delegate.resume.bind(this._delegate);
- }
- Object.defineProperty(UploadTaskCompat.prototype, "snapshot", {
- get: function () {
- return new UploadTaskSnapshotCompat(this._delegate.snapshot, this, this._ref);
- },
- enumerable: false,
- configurable: true
- });
- UploadTaskCompat.prototype.then = function (onFulfilled, onRejected) {
- var _this = this;
- return this._delegate.then(function (snapshot) {
- if (onFulfilled) {
- return onFulfilled(new UploadTaskSnapshotCompat(snapshot, _this, _this._ref));
- }
- }, onRejected);
- };
- UploadTaskCompat.prototype.on = function (type, nextOrObserver, error, completed) {
- var _this = this;
- var wrappedNextOrObserver = undefined;
- if (!!nextOrObserver) {
- if (typeof nextOrObserver === 'function') {
- wrappedNextOrObserver = function (taskSnapshot) {
- return nextOrObserver(new UploadTaskSnapshotCompat(taskSnapshot, _this, _this._ref));
- };
- }
- else {
- wrappedNextOrObserver = {
- next: !!nextOrObserver.next
- ? function (taskSnapshot) {
- return nextOrObserver.next(new UploadTaskSnapshotCompat(taskSnapshot, _this, _this._ref));
- }
- : undefined,
- complete: nextOrObserver.complete || undefined,
- error: nextOrObserver.error || undefined
- };
- }
- }
- return this._delegate.on(type, wrappedNextOrObserver, error || undefined, completed || undefined);
- };
- return UploadTaskCompat;
- }());
-
- var ListResultCompat = (function () {
- function ListResultCompat(_delegate, _service) {
- this._delegate = _delegate;
- this._service = _service;
- }
- Object.defineProperty(ListResultCompat.prototype, "prefixes", {
- get: function () {
- var _this = this;
- return this._delegate.prefixes.map(function (ref) { return new ReferenceCompat(ref, _this._service); });
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(ListResultCompat.prototype, "items", {
- get: function () {
- var _this = this;
- return this._delegate.items.map(function (ref) { return new ReferenceCompat(ref, _this._service); });
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(ListResultCompat.prototype, "nextPageToken", {
- get: function () {
- return this._delegate.nextPageToken || null;
- },
- enumerable: false,
- configurable: true
- });
- return ListResultCompat;
- }());
-
-
- var ReferenceCompat = (function () {
- function ReferenceCompat(_delegate, storage) {
- this._delegate = _delegate;
- this.storage = storage;
- }
- Object.defineProperty(ReferenceCompat.prototype, "name", {
- get: function () {
- return this._delegate.name;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(ReferenceCompat.prototype, "bucket", {
- get: function () {
- return this._delegate.bucket;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(ReferenceCompat.prototype, "fullPath", {
- get: function () {
- return this._delegate.fullPath;
- },
- enumerable: false,
- configurable: true
- });
- ReferenceCompat.prototype.toString = function () {
- return this._delegate.toString();
- };
-
-
- ReferenceCompat.prototype.child = function (childPath) {
- var reference = storage._getChild(this._delegate, childPath);
- return new ReferenceCompat(reference, this.storage);
- };
- Object.defineProperty(ReferenceCompat.prototype, "root", {
- get: function () {
- return new ReferenceCompat(this._delegate.root, this.storage);
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(ReferenceCompat.prototype, "parent", {
-
-
- get: function () {
- var reference = this._delegate.parent;
- if (reference == null) {
- return null;
- }
- return new ReferenceCompat(reference, this.storage);
- },
- enumerable: false,
- configurable: true
- });
-
-
- ReferenceCompat.prototype.put = function (data, metadata) {
- this._throwIfRoot('put');
- return new UploadTaskCompat(storage.uploadBytesResumable(this._delegate, data, metadata), this);
- };
-
-
- ReferenceCompat.prototype.putString = function (value, format, metadata) {
- if (format === void 0) { format = storage.StringFormat.RAW; }
- this._throwIfRoot('putString');
- var data = storage._dataFromString(format, value);
- var metadataClone = tslib.__assign({}, metadata);
- if (metadataClone['contentType'] == null && data.contentType != null) {
- metadataClone['contentType'] = data.contentType;
- }
- return new UploadTaskCompat(new storage._UploadTask(this._delegate, new storage._FbsBlob(data.data, true), metadataClone), this);
- };
-
-
- ReferenceCompat.prototype.listAll = function () {
- var _this = this;
- return storage.listAll(this._delegate).then(function (r) { return new ListResultCompat(r, _this.storage); });
- };
-
-
- ReferenceCompat.prototype.list = function (options) {
- var _this = this;
- return storage.list(this._delegate, options || undefined).then(function (r) { return new ListResultCompat(r, _this.storage); });
- };
-
-
- ReferenceCompat.prototype.getMetadata = function () {
- return storage.getMetadata(this._delegate);
- };
-
-
- ReferenceCompat.prototype.updateMetadata = function (metadata) {
- return storage.updateMetadata(this._delegate, metadata);
- };
-
-
- ReferenceCompat.prototype.getDownloadURL = function () {
- return storage.getDownloadURL(this._delegate);
- };
-
-
- ReferenceCompat.prototype.delete = function () {
- this._throwIfRoot('delete');
- return storage.deleteObject(this._delegate);
- };
- ReferenceCompat.prototype._throwIfRoot = function (name) {
- if (this._delegate._location.path === '') {
- throw storage._invalidRootOperation(name);
- }
- };
- return ReferenceCompat;
- }());
-
-
-
- var StorageServiceCompat = (function () {
- function StorageServiceCompat(app, _delegate) {
- this.app = app;
- this._delegate = _delegate;
- }
- Object.defineProperty(StorageServiceCompat.prototype, "maxOperationRetryTime", {
- get: function () {
- return this._delegate.maxOperationRetryTime;
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(StorageServiceCompat.prototype, "maxUploadRetryTime", {
- get: function () {
- return this._delegate.maxUploadRetryTime;
- },
- enumerable: false,
- configurable: true
- });
-
-
- StorageServiceCompat.prototype.ref = function (path) {
- if (isUrl(path)) {
- throw storage._invalidArgument('ref() expected a child path but got a URL, use refFromURL instead.');
- }
- return new ReferenceCompat(storage.ref(this._delegate, path), this);
- };
-
-
- StorageServiceCompat.prototype.refFromURL = function (url) {
- if (!isUrl(url)) {
- throw storage._invalidArgument('refFromURL() expected a full URL but got a child path, use ref() instead.');
- }
- try {
- storage._Location.makeFromUrl(url, this._delegate.host);
- }
- catch (e) {
- throw storage._invalidArgument('refFromUrl() expected a valid full URL but got an invalid one.');
- }
- return new ReferenceCompat(storage.ref(this._delegate, url), this);
- };
- StorageServiceCompat.prototype.setMaxUploadRetryTime = function (time) {
- this._delegate.maxUploadRetryTime = time;
- };
- StorageServiceCompat.prototype.setMaxOperationRetryTime = function (time) {
- this._delegate.maxOperationRetryTime = time;
- };
- StorageServiceCompat.prototype.useEmulator = function (host, port, options) {
- if (options === void 0) { options = {}; }
- storage.connectStorageEmulator(this._delegate, host, port, options);
- };
- return StorageServiceCompat;
- }());
- function isUrl(path) {
- return /^[A-Za-z]+:\/\//.test(path);
- }
-
- var name = "@firebase/storage-compat";
- var version = "0.2.1";
-
-
-
- var STORAGE_TYPE = 'storage-compat';
- function factory(container, _a) {
- var url = _a.instanceIdentifier;
-
- var app = container.getProvider('app-compat').getImmediate();
- var storageExp = container
- .getProvider('storage')
- .getImmediate({ identifier: url });
- var storageServiceCompat = new StorageServiceCompat(app, storageExp);
- return storageServiceCompat;
- }
- function registerStorage(instance) {
- var namespaceExports = {
-
- TaskState: storage._TaskState,
- TaskEvent: storage._TaskEvent,
- StringFormat: storage.StringFormat,
- Storage: StorageServiceCompat,
- Reference: ReferenceCompat
- };
- instance.INTERNAL.registerComponent(new component.Component(STORAGE_TYPE, factory, "PUBLIC" )
- .setServiceProps(namespaceExports)
- .setMultipleInstances(true));
- instance.registerVersion(name, version);
- }
- registerStorage(firebase__default["default"]);
-
- exports.registerStorage = registerStorage;
|