Commit ea3625b6 authored by nanahira's avatar nanahira

first

parent 1f601c33
Pipeline #6782 failed with stages
in 30 seconds
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
\ 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
\ 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.
# typed-reflector
`reflect-metadata` with typing support.
\ No newline at end of file
Metadata reflector with typing support.
## API
### Type Map
Either Reflector or Metadata Setter accepts 2 type arguments. The first one is the type map of common types, while the second one is the type map of arrays.
### Reflector
* `Reflector.get(metadataKey, instance, key)` Fetches the metadata of instance.
* `Reflector.getArray(metadataKey, instance, key)` Fetches the array metadata of instance. Will return empty array if not exists.
* `Reflector.getProperty(metadataKey, instance, key, alternate = instance)` Fetches the array metadata of instance from both class and property. The last parameter is an alternate source object for fetching metadata from class.
### Metadata Setter
* `Metadata.set(metadataKey, value)` Sets and overrides the metadata.
* `Metadata.append(metadataKey, value)` Append to the the metadata array. The array would be created if not exists.
* `Metadata.appendUnique(metadataKey, value)` Same as above but no duplicate values.
* `Metadata.concat(metadataKey, value)` The value must be an array, and the metadata array would be joined together.
#!/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
{
"name": "typed-reflector",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "typed-reflector",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"reflect-metadata": "^0.1.13"
}
},
"node_modules/reflect-metadata": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
"integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg=="
}
},
"dependencies": {
"reflect-metadata": {
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
"integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg=="
}
}
}
{
"name": "typed-reflector",
"version": "1.0.0",
"description": "Metadata reflector with typing support.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/typed-reflector.git"
},
"bugs": {
"url": "https://code.mycard.moe/3rdeye/typed-reflector/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/typed-reflector",
"keywords": [
"reflect",
"reflector",
"reflect-metadata"
],
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"dependencies": {
"reflect-metadata": "^0.1.13"
}
}
export * from './interfaces';
export type StringDict = Record<string, any>;
export type Key<T> = keyof T & string;
export type ArrayValueMap<AM extends StringDict> = {
[K in keyof AM]: AM[K][];
};
export type ArrayValue<
AM extends StringDict,
K extends Key<ArrayValueMap<AM>>
> = ArrayValueMap<AM>[K];
export type MergeKey<M extends StringDict, AM extends StringDict> =
| Key<M>
| Key<AM>;
export type GenericMap<M extends StringDict, AM extends StringDict> = M &
ArrayValueMap<AM>;
export type MapValue<
M extends StringDict,
AM extends StringDict,
K extends MergeKey<M, AM>
> = K extends Key<AM> ? ArrayValue<AM, K> : K extends Key<M> ? M[K] : never;
export * from './reflector';
export * from './setter';
export * from './def';
import 'reflect-metadata';
import { ArrayValue, GenericMap, Key, MapValue, StringDict } from './def';
export class Reflector<M extends StringDict, AM extends StringDict> {
get<K extends Key<GenericMap<M, AM>>>(
metadataKey: K,
instance: any,
key?: string | symbol,
): MapValue<M, AM, K> {
const instanceClass = instance.constructor;
if (key) {
return Reflect.getMetadata(metadataKey, instanceClass, key);
} else {
return Reflect.getMetadata(metadataKey, instanceClass);
}
}
getArray<K extends Key<M>>(
metadataKey: K,
instance: any,
key?: string | symbol,
): ArrayValue<AM, K> {
return this.get(metadataKey, instance, key) || [];
}
getProperty<K extends Key<M>, I = any>(
metadataKey: K,
instance: I,
key: keyof I & (string | symbol),
alternate: any = instance,
): ArrayValue<AM, K> {
const valueFromClass = this.getArray(metadataKey, alternate);
const valueFromProperty = this.getArray(metadataKey, instance, key);
return [...valueFromClass, ...valueFromProperty] as ArrayValue<AM, K>;
}
}
import 'reflect-metadata';
import { ArrayValueMap, GenericMap, Key, MergeKey, StringDict } from './def';
export type AllDecorators = MethodDecorator &
ClassDecorator &
PropertyDecorator;
export class Metadata<M extends StringDict, AM extends StringDict> {
private getMetadataInDecorator<
K extends MergeKey<M, AM>,
GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM>
>(metaKey: K, target: any, key?: any): GM[K] {
const targetClass = target.constructor;
if (key) {
return Reflect.getMetadata(metaKey, targetClass, key);
} else {
return Reflect.getMetadata(metaKey, targetClass);
}
}
private setMetadataInDecorator<
K extends MergeKey<M, AM>,
GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM>
>(metaKey: K, value: GM[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);
}
}
transform<
K extends MergeKey<M, AM>,
IK extends Key<AM>,
GM extends Record<MergeKey<M, AM>, any> = GenericMap<M, AM>
>(
metadataKey: K,
metadataValueFun: (oldValue: GM[K]) => GM[K],
keysIndexMeta?: IK,
): AllDecorators {
return (target: any, key?: any, descriptor?: any) => {
const oldValue = this.getMetadataInDecorator<K, GM>(
metadataKey,
target,
key,
);
const newValue = metadataValueFun(oldValue);
this.setMetadataInDecorator(metadataKey, newValue, target, key);
if (keysIndexMeta) {
const keysDec = this.append<IK, any>(keysIndexMeta, key);
keysDec(target);
}
if (descriptor) {
return descriptor;
}
return target;
};
}
set<K extends MergeKey<M, AM>, IK extends Key<AM>>(
metadataKey: K,
metadataValue: GenericMap<M, AM>[K],
keysIndexMeta?: IK,
) {
return this.transform<K, IK>(
metadataKey,
() => metadataValue,
keysIndexMeta,
);
}
append<K extends Key<AM>, IK extends Key<AM>>(
metadataKey: K,
metadataValue: AM[K],
keysIndexMeta?: IK,
) {
return this.transform<K, IK, ArrayValueMap<AM>>(
metadataKey,
(arr) => {
const newArr = arr || [];
newArr.push(metadataValue);
return newArr;
},
keysIndexMeta,
);
}
appendUnique<K extends Key<AM>, IK extends Key<AM>>(
metadataKey: K,
metadataValue: AM[K],
keysIndexMeta?: IK,
) {
return this.transform<K, IK, ArrayValueMap<AM>>(
metadataKey,
(arr) => {
const newArr = arr || [];
if (newArr.includes(metadataValue)) {
return newArr;
}
newArr.push(metadataValue);
return newArr;
},
keysIndexMeta,
);
}
concat<K extends Key<AM>, IK extends Key<AM>>(
metadataKey: K,
metadataValue: ArrayValueMap<AM>[K],
keysIndexMeta?: IK,
) {
return this.transform<K, IK, ArrayValueMap<AM>>(
metadataKey,
(arr) => (arr || []).concat(metadataValue),
keysIndexMeta,
);
}
}
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es2020",
"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