12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = exports.AdaptableController = void 0;
- var _adapter = Symbol();
- class AdaptableController {
- constructor(adapter, appId, options) {
- this.options = options;
- this.appId = appId;
- this.adapter = adapter;
- }
- set adapter(adapter) {
- this.validateAdapter(adapter);
- this[_adapter] = adapter;
- }
- get adapter() {
- return this[_adapter];
- }
- expectedAdapterType() {
- throw new Error('Subclasses should implement expectedAdapterType()');
- }
- validateAdapter(adapter) {
- AdaptableController.validateAdapter(adapter, this);
- }
- static validateAdapter(adapter, self, ExpectedType) {
- if (!adapter) {
- throw new Error(this.constructor.name + ' requires an adapter');
- }
- const Type = ExpectedType || self.expectedAdapterType();
-
- if (!Type) {
- return;
- }
-
- const mismatches = Object.getOwnPropertyNames(Type.prototype).reduce((obj, key) => {
- const adapterType = typeof adapter[key];
- const expectedType = typeof Type.prototype[key];
- if (adapterType !== expectedType) {
- obj[key] = {
- expected: expectedType,
- actual: adapterType
- };
- }
- return obj;
- }, {});
- if (Object.keys(mismatches).length > 0) {
- throw new Error("Adapter prototype don't match expected prototype", adapter, mismatches);
- }
- }
- }
- exports.AdaptableController = AdaptableController;
- var _default = exports.default = AdaptableController;
|