47 lines
2.7 KiB
JavaScript
47 lines
2.7 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.applySettingDefaults = exports.isBrowser = exports.ensureTrailingSlash = exports.uuid = void 0;
|
|
function uuid() {
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
return v.toString(16);
|
|
});
|
|
}
|
|
exports.uuid = uuid;
|
|
function ensureTrailingSlash(url) {
|
|
return url.endsWith('/') ? url : url + '/';
|
|
}
|
|
exports.ensureTrailingSlash = ensureTrailingSlash;
|
|
const isBrowser = () => typeof window !== 'undefined';
|
|
exports.isBrowser = isBrowser;
|
|
function applySettingDefaults(options, defaults) {
|
|
var _a, _b;
|
|
const { db: dbOptions, auth: authOptions, realtime: realtimeOptions, global: globalOptions, } = options;
|
|
const { db: DEFAULT_DB_OPTIONS, auth: DEFAULT_AUTH_OPTIONS, realtime: DEFAULT_REALTIME_OPTIONS, global: DEFAULT_GLOBAL_OPTIONS, } = defaults;
|
|
const result = {
|
|
db: Object.assign(Object.assign({}, DEFAULT_DB_OPTIONS), dbOptions),
|
|
auth: Object.assign(Object.assign({}, DEFAULT_AUTH_OPTIONS), authOptions),
|
|
realtime: Object.assign(Object.assign({}, DEFAULT_REALTIME_OPTIONS), realtimeOptions),
|
|
global: Object.assign(Object.assign(Object.assign({}, DEFAULT_GLOBAL_OPTIONS), globalOptions), { headers: Object.assign(Object.assign({}, ((_a = DEFAULT_GLOBAL_OPTIONS === null || DEFAULT_GLOBAL_OPTIONS === void 0 ? void 0 : DEFAULT_GLOBAL_OPTIONS.headers) !== null && _a !== void 0 ? _a : {})), ((_b = globalOptions === null || globalOptions === void 0 ? void 0 : globalOptions.headers) !== null && _b !== void 0 ? _b : {})) }),
|
|
accessToken: () => __awaiter(this, void 0, void 0, function* () { return ''; }),
|
|
};
|
|
if (options.accessToken) {
|
|
result.accessToken = options.accessToken;
|
|
}
|
|
else {
|
|
// hack around Required<>
|
|
delete result.accessToken;
|
|
}
|
|
return result;
|
|
}
|
|
exports.applySettingDefaults = applySettingDefaults;
|
|
//# sourceMappingURL=helpers.js.map
|