mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(extensions): implementation
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@dbeaver/core/extensions",
|
||||
"private": true,
|
||||
"sideEffects": false,
|
||||
"main": "../dist/extensions",
|
||||
"module": "../dist/extensions",
|
||||
"types": "../dist/types/extensions"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* cloudbeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { EXTENSION_SYMBOL, EXTENSION_TYPE_SYMBOL } from './constants';
|
||||
|
||||
|
||||
export interface IExtension<T> {
|
||||
[EXTENSION_SYMBOL]: symbol;
|
||||
[EXTENSION_TYPE_SYMBOL]?: T;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* cloudbeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
export const EXTENSION_SYMBOL = Symbol('@extension');
|
||||
export const EXTENSION_TYPE_SYMBOL = Symbol('@extension/type');
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* cloudbeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { EXTENSION_SYMBOL } from './constants';
|
||||
import { IExtension } from './IExtension';
|
||||
|
||||
export function createExtension<T>(
|
||||
extension: object,
|
||||
key: symbol
|
||||
): IExtension<T> {
|
||||
return Object.assign(extension, { [EXTENSION_SYMBOL]: key });
|
||||
}
|
||||
|
||||
export function isExtension<T>(
|
||||
obj: any,
|
||||
key?: symbol,
|
||||
): obj is IExtension<T> {
|
||||
if (!(EXTENSION_SYMBOL in obj)) {
|
||||
return false;
|
||||
}
|
||||
if (key && obj[EXTENSION_SYMBOL] !== key) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './IExtension';
|
||||
export * from './createExtension';
|
||||
Reference in New Issue
Block a user