Commit 3882b603 authored by nanahira's avatar nanahira

first

parent 7a7967e7
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
/test
/dist/test
\ No newline at end of file
stages:
- build
- combine
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_TEST_ARM_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
CONTAINER_TEST_X86_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build-x86:
stage: build
tags:
- docker
script:
- TARGET_IMAGE=$CONTAINER_TEST_X86_IMAGE
- docker build --pull -t $TARGET_IMAGE .
- docker push $TARGET_IMAGE
build-arm:
stage: build
tags:
- docker-arm
script:
- TARGET_IMAGE=$CONTAINER_TEST_ARM_IMAGE
- docker build --pull -t $TARGET_IMAGE .
- docker push $TARGET_IMAGE
combine:
stage: combine
tags:
- docker
script:
- TARGET_IMAGE=$CONTAINER_TEST_IMAGE
- SOURCE_IMAGE_2=$CONTAINER_TEST_ARM_IMAGE
- SOURCE_IMAGE_1=$CONTAINER_TEST_X86_IMAGE
- docker pull $SOURCE_IMAGE_1
- docker pull $SOURCE_IMAGE_2
- docker manifest create $TARGET_IMAGE --amend $SOURCE_IMAGE_1 --amend
$SOURCE_IMAGE_2
- docker manifest push $TARGET_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- TARGET_IMAGE=$CONTAINER_RELEASE_IMAGE
- SOURCE_IMAGE=$CONTAINER_TEST_IMAGE
- docker pull $SOURCE_IMAGE
- docker tag $SOURCE_IMAGE $TARGET_IMAGE
- docker push $TARGET_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
script:
- TARGET_IMAGE=$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- SOURCE_IMAGE=$CONTAINER_TEST_IMAGE
- docker pull $SOURCE_IMAGE
- docker tag $SOURCE_IMAGE $TARGET_IMAGE
- docker push $TARGET_IMAGE
only:
- tags
/install-npm.sh
.git*
/data
/output
/config.yaml
.idea
.dockerignore
Dockerfile
/test
/dist/test
\ No newline at end of file
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
MIT License
Copyright (c) 2019-present Shigma
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
export * from './src/register';
export * from './src/decorators';
export * from './src/def';
#!/bin/bash
npm install --save-dev \
@types/node \
typescript \
'@typescript-eslint/eslint-plugin@^4.28.2' \
'@typescript-eslint/parser@^4.28.2 '\
'eslint@^7.30.0' \
'eslint-config-prettier@^8.3.0' \
'eslint-plugin-prettier@^3.4.0' \
prettier
This diff is collapsed.
{
"name": "koishi-thirdeye",
"version": "1.0.0",
"description": "DI plugin framework for Koishi v4 beta",
"main": "dist/index.js",
"scripts": {
"build": "tsc"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/koishi-thirdeye"
},
"keywords": [
"Koishi",
"qqbot",
"cqbot",
"cqhttp",
"onebot"
],
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"devDependencies": {
"@koishijs/plugin-adapter-onebot": "^4.0.0-beta.0",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"koishi": "^4.0.0-beta.0",
"prettier": "^2.4.1",
"typescript": "^4.4.4",
"ws": "^8.2.3"
},
"peerDependencies": {
"koishi": "^4.0.0-beta.0"
},
"dependencies": {
"koishi-utils-schemagen": "^1.1.9",
"reflect-metadata": "^0.1.13"
}
}
import {
CommandDefinitionFun,
CommandPutConfig,
CommandPutConfigMap,
EventName,
GenerateMappingStruct,
KoishiCommandDefinition,
KoishiCommandPutDef,
KoishiDoRegister,
KoishiDoRegisterKeys,
KoishiOnContextScope,
KoishiServiceInjectSym,
KoishiServiceInjectSymKeys,
KoishiServiceProvideSym,
KoishiSystemInjectSym,
KoishiSystemInjectSymKeys,
MetadataGenericMap,
OnContextFunction,
Selection,
} from './def';
import 'reflect-metadata';
import { App, Argv, Command, Context, FieldCollector, Session } from 'koishi';
import {
AppendMetadata,
AppendMetadataUnique,
ConcatMetadata,
SetMetadata,
} from './meta/metadata.decorators';
import { PluginClass } from './register';
// Register methods
export const DoRegister = (
value: MetadataGenericMap['KoishiDoRegister'],
): MethodDecorator =>
SetMetadata(KoishiDoRegister, value, KoishiDoRegisterKeys);
export const UseMiddleware = (prepend?: boolean): MethodDecorator =>
DoRegister(GenerateMappingStruct('middleware', prepend));
export const UseEvent = (name: EventName, prepend?: boolean): MethodDecorator =>
DoRegister(GenerateMappingStruct('onevent', { name, prepend }));
export const UsePlugin = (): MethodDecorator =>
DoRegister(GenerateMappingStruct('plugin'));
export function UseCommand<D extends string>(
def: D,
config?: Command.Config,
): MethodDecorator;
export function UseCommand<D extends string>(
def: D,
desc: string,
config?: Command.Config,
): MethodDecorator;
export function UseCommand(
def: string,
...args: [Command.Config?] | [string, Command.Config?]
): MethodDecorator {
const desc = typeof args[0] === 'string' ? (args.shift() as string) : '';
const config = args[0] as Command.Config;
return (obj, key: string, des) => {
const putOptions: CommandPutConfig<keyof CommandPutConfigMap>[] =
Reflect.getMetadata(KoishiCommandPutDef, obj.constructor, key) ||
undefined;
const metadataDec = DoRegister({
type: 'command',
data: {
def,
desc,
config,
putOptions,
},
});
return metadataDec(obj, key, des);
};
}
// Context scopes
export const OnContext = (
ctxFun: OnContextFunction,
): MethodDecorator & ClassDecorator =>
AppendMetadata(KoishiOnContextScope, ctxFun);
export const OnUser = (...values: string[]) =>
OnContext((ctx) => ctx.user(...values));
export const OnSelf = (...values: string[]) =>
OnContext((ctx) => ctx.self(...values));
export const OnGuild = (...values: string[]) =>
OnContext((ctx) => ctx.guild(...values));
export const OnChannel = (...values: string[]) =>
OnContext((ctx) => ctx.channel(...values));
export const OnPlatform = (...values: string[]) =>
OnContext((ctx) => ctx.platform(...values));
export const OnPrivate = (...values: string[]) =>
OnContext((ctx) => ctx.private(...values));
export const OnSelection = (selection: Selection) =>
OnContext((ctx) => ctx.select(selection));
// Command definition
export const CommandDef = (def: CommandDefinitionFun): MethodDecorator =>
AppendMetadata(KoishiCommandDefinition, def);
export const CommandDescription = (desc: string) =>
CommandDef((cmd) => {
cmd.description = desc;
return cmd;
});
export const CommandAlias = (...names: string[]) =>
CommandDef((cmd) => cmd.alias(...names));
export const CommandShortcut = (
name: string | RegExp,
config: Command.Shortcut = {},
) => CommandDef((cmd) => cmd.shortcut(name, config));
export const CommandUsage = (text: string) =>
CommandDef((cmd) => cmd.usage(text));
export const CommandExample = (text: string) =>
CommandDef((cmd) => cmd.example(text));
export const CommandOption = (
name: string,
desc: string,
config: Argv.OptionConfig = {},
) => CommandDef((cmd) => cmd.option(name, desc, config));
export const CommandUserFields = (fields: FieldCollector<'user'>) =>
CommandDef((cmd) => cmd.userFields(fields));
export const CommandChannelFields = (fields: FieldCollector<'channel'>) =>
CommandDef((cmd) => cmd.channelFields(fields));
// Command put config
function PutCommandParam<T extends keyof CommandPutConfigMap>(
type: T,
data?: CommandPutConfigMap[T],
): ParameterDecorator {
return (obj, key: string, index) => {
const objClass = obj.constructor;
const list: CommandPutConfig<T>[] =
Reflect.getMetadata(KoishiCommandPutDef, objClass, key) || [];
list[index] = GenerateMappingStruct(type, data);
Reflect.defineMetadata(KoishiCommandPutDef, list, objClass, key);
};
}
export const PutArgv = () => PutCommandParam('argv');
export const PutSession = (field?: keyof Session) =>
field ? PutCommandParam('sessionField', field) : PutCommandParam('session');
export const PutArg = (i: number) => PutCommandParam('arg', i);
export const PutOption = (
name: string,
desc: string,
config: Argv.OptionConfig = {},
) => PutCommandParam('option', { name, desc, config });
export const PutUser = (field: FieldCollector<'user'>) =>
PutCommandParam('user', field);
export const PutChannel = (field: FieldCollector<'channel'>) =>
PutCommandParam('channel', field);
export const PutUserName = (useDatabase = true) =>
PutCommandParam('username', useDatabase);
export const PutUserId = () => PutSession('userId');
export const PutGuildId = () => PutSession('guildId');
export const PutGuildName = () => PutSession('guildName');
export const PutChannelId = () => PutSession('channelId');
export const PutChannelName = () => PutSession('channelName');
export const PutSelfId = () => PutSession('selfId');
export const PutBot = () => PutSession('bot');
// Service
export function Inject(name?: keyof Context.Services): PropertyDecorator {
return (obj, key) => {
if (!name) {
const functionType = Reflect.getMetadata('design:type', obj, key);
let dec: PropertyDecorator;
if (functionType === Context) {
dec = InjectContext();
} else if (functionType === App) {
dec = InjectApp();
}
if (dec) {
return dec(obj, key);
}
}
const serviceName = name || (key as keyof Context.Services);
const dec = SetMetadata(
KoishiServiceInjectSym,
serviceName,
KoishiServiceInjectSymKeys,
);
return dec(obj, key);
};
}
export function Provide(
name: keyof Context.Services,
options?: Context.Options,
): ClassDecorator {
Context.service(name, options);
return AppendMetadataUnique(KoishiServiceProvideSym, name);
}
const InjectSystem = (fun: (obj: PluginClass) => any) =>
SetMetadata(KoishiSystemInjectSym, fun, KoishiSystemInjectSymKeys);
export const InjectContext = (select?: Selection) =>
InjectSystem((obj) => {
if (select) {
return obj.__ctx.select(select);
} else {
return obj.__ctx;
}
});
export const InjectApp = () => InjectSystem((obj) => obj.__ctx.app);
export const InjectConfig = (raw = false) =>
InjectSystem((obj) => (raw ? obj.__rawConfig : obj.__config));
// metadatas
import { Context } from 'koishi';
import {
CommandDefinitionFun,
DoRegisterConfig,
OnContextFunction,
} from './interfaces';
import { PluginClass } from '../register';
export const KoishiOnContextScope = 'KoishiOnContextScope';
export const KoishiDoRegister = 'KoishiDoRegister';
export const KoishiDoRegisterKeys = 'KoishiDoRegisterKeys';
export const KoishiCommandDefinition = 'KoishiCommandDefinition';
export const KoishiCommandPutDef = 'KoishiCommandPutDef';
export const KoishiServiceInjectSym = 'KoishiServiceInjectSym';
export const KoishiServiceInjectSymKeys = 'KoishiServiceInjectSymKeys';
export const KoishiServiceProvideSym = 'KoishiServiceProvideSym';
export const KoishiSystemInjectSym = 'KoishiSystemInjectSym';
export const KoishiSystemInjectSymKeys = 'KoishiSystemInjectSymKeys';
// metadata map
export interface MetadataArrayMap {
KoishiOnContextScope: OnContextFunction;
KoishiCommandDefinition: CommandDefinitionFun;
KoishiServiceProvideSym: keyof Context.Services;
KoishiDoRegisterKeys: string;
KoishiServiceInjectSymKeys: string;
KoishiSystemInjectSymKeys: string;
}
export interface MetadataMap {
KoishiDoRegister: DoRegisterConfig;
KoishiServiceInjectSym: keyof Context.Services;
KoishiSystemInjectSym: (obj: PluginClass) => any;
}
export * from './interfaces';
export * from './constants';
import {
App,
Argv,
Channel,
Command,
Context,
EventMap,
FieldCollector,
MaybeArray,
Modules,
Plugin,
Session,
User,
} from 'koishi';
import { MetadataArrayMap, MetadataMap } from './constants';
export interface Type<T = any> extends Function {
new (...args: any[]): T;
}
const selectors = [
'user',
'guild',
'channel',
'self',
'private',
'platform',
] as const;
type SelectorType = typeof selectors[number];
type SelectorValue = boolean | MaybeArray<string | number>;
type BaseSelection = { [K in SelectorType as `$${K}`]?: SelectorValue };
export interface Selection extends BaseSelection {
$and?: Selection[];
$or?: Selection[];
$not?: Selection;
}
export interface ContextSelector {
select?: Selection;
useSelector?: OnContextFunction;
}
export type KoishiPluginOptions<T extends keyof Modules | Plugin> =
| boolean
| (T extends keyof Modules
? Plugin.ModuleConfig<Modules[T]>
: T extends Plugin
? Plugin.Config<T>
: never);
export interface KoishiModulePlugin<T extends keyof Modules | Plugin>
extends ContextSelector {
plugin: T;
options?: boolean | KoishiPluginOptions<T>;
}
export function PluginDef<T extends keyof Modules>(
plugin: T,
options?: boolean | Plugin.ModuleConfig<Modules[T]>,
select?: Selection,
): KoishiModulePlugin<T>;
export function PluginDef<T extends Plugin>(
plugin: T,
options?: boolean | Plugin.Config<T>,
select?: Selection,
): KoishiModulePlugin<T>;
export function PluginDef<T extends keyof Modules | Plugin>(
plugin: T,
options?: KoishiPluginOptions<T>,
select?: Selection,
): KoishiModulePlugin<T> {
return { plugin, options, select };
}
export type EventName = keyof EventMap;
export interface EventNameAndPrepend {
name: EventName;
prepend?: boolean;
}
export type ContextFunction<T> = (ctx: Context) => T;
export type OnContextFunction = ContextFunction<Context>;
export interface DoRegisterConfigDataMap {
middleware: boolean; // prepend
onevent: EventNameAndPrepend;
plugin: never;
command: CommandRegisterConfig;
}
export interface MappingStruct<
T extends Record<string | number | symbol, any>,
K extends keyof T
> {
type: K;
data?: T[K];
}
export function GenerateMappingStruct<
T extends Record<string | number | symbol, any>,
K extends keyof T
>(type: K, data?: T[K]): MappingStruct<T, K> {
return {
type,
data,
};
}
export type DoRegisterConfig<
K extends keyof DoRegisterConfigDataMap = keyof DoRegisterConfigDataMap
> = MappingStruct<DoRegisterConfigDataMap, K>;
// Command stuff
export interface CommandRegisterConfig<D extends string = string> {
def: D;
desc?: string;
config?: Command.Config;
putOptions?: CommandPutConfig<keyof CommandPutConfigMap>[];
}
export interface CommandOptionConfig {
name: string;
desc: string;
config?: Argv.OptionConfig;
}
export interface CommandPutConfigMap {
arg: number;
argv: never;
session: never;
option: CommandOptionConfig;
user: FieldCollector<'user'>;
channel: FieldCollector<'channel'>;
username: boolean;
sessionField: keyof Session;
}
export type CommandPutConfig<
K extends keyof CommandPutConfigMap = keyof CommandPutConfigMap
> = MappingStruct<CommandPutConfigMap, K>;
export type CommandDefinitionFun = (cmd: Command) => Command;
// metadata map
export type MetadataArrayValueMap = {
[K in keyof MetadataArrayMap]: MetadataArrayMap[K][];
};
export type MetadataGenericMap = MetadataArrayValueMap & MetadataMap;
export type MetadataArrayValue<
K extends keyof MetadataArrayValueMap
> = MetadataArrayValueMap[K];
export type MetadataKey = keyof MetadataArrayMap | keyof MetadataMap;
export type MetadataMapValue<
K extends MetadataKey
> = K extends keyof MetadataArrayValueMap
? MetadataArrayValue<K>
: K extends keyof MetadataMap
? MetadataMap[K]
: never;
// command interceptor
export interface KoishiCommandInterceptor<
U extends User.Field = never,
G extends Channel.Field = never,
A extends any[] = any[],
O extends {} = {}
> {
intercept: Command.Action<U, G, A, O>;
}
export type KoishiCommandInterceptorRegistration<
U extends User.Field = never,
G extends Channel.Field = never,
A extends any[] = any[],
O extends {} = {}
> =
| KoishiCommandInterceptor<U, G, A, O>
| Type<KoishiCommandInterceptor<U, G, A, O>>
| string
| symbol;
import {
MetadataArrayMap,
MetadataArrayValue,
MetadataGenericMap,
MetadataMapValue,
} from '../def';
export function getMetadata<K extends keyof MetadataGenericMap>(
metadataKey: K,
instance: any,
key?: string | symbol,
): MetadataMapValue<K> {
const instanceClass = instance.constructor;
if (key) {
return Reflect.getMetadata(metadataKey, instanceClass, key);
} else {
return Reflect.getMetadata(metadataKey, instanceClass);
}
}
export function getMetadataArray<K extends keyof MetadataArrayMap>(
metadataKey: K,
instance: any,
key?: string | symbol,
): MetadataArrayValue<K> {
return getMetadata(metadataKey, instance, key) || [];
}
export function getPropertyMetadata<K extends keyof MetadataArrayMap, I = any>(
metadataKey: K,
instance: I,
originalClass: any,
key: keyof I & (string | symbol),
): MetadataArrayValue<K> {
const valueFromClass = getMetadataArray(metadataKey, originalClass);
const valueFromProperty = getMetadataArray(metadataKey, instance, key);
return [...valueFromClass, ...valueFromProperty] as MetadataArrayValue<K>;
}
import {
MetadataArrayMap,
MetadataArrayValue,
MetadataArrayValueMap,
MetadataGenericMap,
MetadataKey,
} from '../def';
export type AllDecorators = MethodDecorator &
ClassDecorator &
PropertyDecorator;
function getMetadataInDecorator<
K extends MetadataKey,
VM extends Partial<MetadataGenericMap> = MetadataGenericMap
>(metaKey: K, target: any, key?: any): VM[K] {
const targetClass = target.constructor;
if (key) {
return Reflect.getMetadata(metaKey, targetClass, key);
} else {
return Reflect.getMetadata(metaKey, targetClass);
}
}
function setMetadataInDecorator<
K extends MetadataKey,
VM extends Partial<MetadataGenericMap> = MetadataGenericMap
>(metaKey: K, value: VM[K], target: any, key?: any) {
const targetClass = target.constructor;
if (key) {
return Reflect.defineMetadata(metaKey, value, targetClass, key);
} else {
return Reflect.defineMetadata(metaKey, value, targetClass);
}
}
function TransformMetadata<
K extends MetadataKey,
VM extends Partial<MetadataGenericMap> = MetadataGenericMap
>(
metadataKey: K,
metadataValueFun: (oldValue: VM[K]) => VM[K],
keysIndexMeta?: keyof MetadataArrayMap,
): AllDecorators {
return (target: any, key?: any, descriptor?: any) => {
const oldValue: VM[K] = getMetadataInDecorator(metadataKey, target, key);
const newValue = metadataValueFun(oldValue);
setMetadataInDecorator(metadataKey, newValue, target, key);
if (keysIndexMeta) {
const keysDec = AppendMetadataUnique(keysIndexMeta, key);
keysDec(target);
}
if (descriptor) {
return descriptor;
}
return target;
};
}
export const SetMetadata = <K extends keyof MetadataGenericMap>(
metadataKey: K,
metadataValue: MetadataGenericMap[K],
keysIndexMeta?: keyof MetadataArrayMap,
): AllDecorators =>
TransformMetadata<K>(metadataKey, () => metadataValue, keysIndexMeta);
export const AppendMetadata = <K extends keyof MetadataArrayMap>(
metadataKey: K,
metadataValue: MetadataArrayMap[K],
keysIndexMeta?: keyof MetadataArrayMap,
): AllDecorators =>
TransformMetadata<K, MetadataArrayValueMap>(
metadataKey,
(arr) => {
const newArr = arr || [];
newArr.push(metadataValue);
return newArr;
},
keysIndexMeta,
);
export const AppendMetadataUnique = <K extends keyof MetadataArrayMap>(
metadataKey: K,
metadataValue: MetadataArrayMap[K],
keysIndexMeta?: keyof MetadataArrayMap,
): AllDecorators =>
TransformMetadata<K, MetadataArrayValueMap>(
metadataKey,
(arr) => {
const newArr = arr || [];
if (newArr.includes(metadataValue)) {
return newArr;
}
newArr.push(metadataValue);
return newArr;
},
keysIndexMeta,
);
export const ConcatMetadata = <K extends keyof MetadataArrayValueMap>(
metadataKey: K,
metadataValue: MetadataArrayValue<K>,
keysIndexMeta?: keyof MetadataArrayMap,
): AllDecorators =>
TransformMetadata<K, MetadataArrayValueMap>(
metadataKey,
(arr) => ((arr || []) as any[]).concat(metadataValue),
keysIndexMeta,
);
This diff is collapsed.
import { Context } from 'koishi';
import { ContextSelector } from '../def';
export function getStringFromNativeType(nativeType: any) {
if (!nativeType) {
return;
}
const nativeTypeString = nativeType.toString() as string;
if (!nativeTypeString) {
return;
}
if (nativeTypeString.startsWith('class')) {
return 'class';
}
if (!nativeTypeString.startsWith('function ')) {
return;
}
return nativeType.name?.toLowerCase();
}
export function applySelector(
ctx: Context,
selector: ContextSelector,
): Context {
if (!selector) {
return ctx;
}
let targetCtx = ctx;
if (selector.select) {
targetCtx = targetCtx.select(selector.select);
}
if (selector.useSelector) {
targetCtx = selector.useSelector(targetCtx) || targetCtx;
}
return targetCtx;
}
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es2021",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/**/*.ts",
"test/**/*.ts"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment