@allgemein/schema-api 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +34 -0
- package/api/IBaseRef.d.ts +44 -0
- package/api/IBaseRef.js +4 -0
- package/api/IBaseRef.js.map +1 -0
- package/api/IBuildOptions.d.ts +31 -0
- package/api/IBuildOptions.js +4 -0
- package/api/IBuildOptions.js.map +1 -0
- package/api/IClassRef.d.ts +24 -0
- package/api/IClassRef.js +13 -0
- package/api/IClassRef.js.map +1 -0
- package/api/IEntityRef.d.ts +16 -0
- package/api/IEntityRef.js +11 -0
- package/api/IEntityRef.js.map +1 -0
- package/api/IJsonSchema.d.ts +11 -0
- package/api/IJsonSchema.js +26 -0
- package/api/IJsonSchema.js.map +1 -0
- package/api/ILookupRegistry.d.ts +60 -0
- package/api/ILookupRegistry.js +17 -0
- package/api/ILookupRegistry.js.map +1 -0
- package/api/IPropertyExtentions.d.ts +8 -0
- package/api/IPropertyExtentions.js +5 -0
- package/api/IPropertyExtentions.js.map +1 -0
- package/api/IPropertyRef.d.ts +28 -0
- package/api/IPropertyRef.js +13 -0
- package/api/IPropertyRef.js.map +1 -0
- package/api/ISchemaRef.d.ts +8 -0
- package/api/ISchemaRef.js +4 -0
- package/api/ISchemaRef.js.map +1 -0
- package/api/ISerializeSupport.d.ts +11 -0
- package/api/ISerializeSupport.js +26 -0
- package/api/ISerializeSupport.js.map +1 -0
- package/browser.d.ts +62 -0
- package/browser.js +117 -0
- package/browser.js.map +1 -0
- package/decorators/Embeddable.d.ts +2 -0
- package/decorators/Embeddable.js +14 -0
- package/decorators/Embeddable.js.map +1 -0
- package/decorators/Entity.d.ts +2 -0
- package/decorators/Entity.js +14 -0
- package/decorators/Entity.js.map +1 -0
- package/decorators/Namespace.d.ts +1 -0
- package/decorators/Namespace.js +20 -0
- package/decorators/Namespace.js.map +1 -0
- package/decorators/Property.d.ts +3 -0
- package/decorators/Property.js +59 -0
- package/decorators/Property.js.map +1 -0
- package/decorators/PropertyOf.d.ts +2 -0
- package/decorators/PropertyOf.js +28 -0
- package/decorators/PropertyOf.js.map +1 -0
- package/decorators/Schema.d.ts +2 -0
- package/decorators/Schema.js +14 -0
- package/decorators/Schema.js.map +1 -0
- package/decorators/validate/Hostname.d.ts +6 -0
- package/decorators/validate/Hostname.js +38 -0
- package/decorators/validate/Hostname.js.map +1 -0
- package/decorators/validate/Ip4.d.ts +6 -0
- package/decorators/validate/Ip4.js +37 -0
- package/decorators/validate/Ip4.js.map +1 -0
- package/decorators/validate/Ip6.d.ts +5 -0
- package/decorators/validate/Ip6.js +37 -0
- package/decorators/validate/Ip6.js.map +1 -0
- package/decorators/validate/IsEmail.d.ts +5 -0
- package/decorators/validate/IsEmail.js +37 -0
- package/decorators/validate/IsEmail.js.map +1 -0
- package/decorators/validate/IsNotEmpty.d.ts +5 -0
- package/decorators/validate/IsNotEmpty.js +36 -0
- package/decorators/validate/IsNotEmpty.js.map +1 -0
- package/decorators/validate/MaxLength.d.ts +6 -0
- package/decorators/validate/MaxLength.js +34 -0
- package/decorators/validate/MaxLength.js.map +1 -0
- package/decorators/validate/MinLength.d.ts +6 -0
- package/decorators/validate/MinLength.js +34 -0
- package/decorators/validate/MinLength.js.map +1 -0
- package/decorators/validate/Regex.d.ts +7 -0
- package/decorators/validate/Regex.js +46 -0
- package/decorators/validate/Regex.js.map +1 -0
- package/decorators/validate/Required.d.ts +5 -0
- package/decorators/validate/Required.js +34 -0
- package/decorators/validate/Required.js.map +1 -0
- package/decorators/validate/index.d.ts +9 -0
- package/decorators/validate/index.js +21 -0
- package/decorators/validate/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/lib/AbstractRef.d.ts +26 -0
- package/lib/AbstractRef.js +126 -0
- package/lib/AbstractRef.js.map +1 -0
- package/lib/AnnotationsHelper.d.ts +7 -0
- package/lib/AnnotationsHelper.js +97 -0
- package/lib/AnnotationsHelper.js.map +1 -0
- package/lib/ClassRef.d.ts +120 -0
- package/lib/ClassRef.js +319 -0
- package/lib/ClassRef.js.map +1 -0
- package/lib/Constants.d.ts +45 -0
- package/lib/Constants.js +65 -0
- package/lib/Constants.js.map +1 -0
- package/lib/DataContainer.d.ts +31 -0
- package/lib/DataContainer.js +148 -0
- package/lib/DataContainer.js.map +1 -0
- package/lib/LookupRegistry.d.ts +36 -0
- package/lib/LookupRegistry.js +106 -0
- package/lib/LookupRegistry.js.map +1 -0
- package/lib/SchemaRef.d.ts +14 -0
- package/lib/SchemaRef.js +51 -0
- package/lib/SchemaRef.js.map +1 -0
- package/lib/SchemaUtils.d.ts +39 -0
- package/lib/SchemaUtils.js +129 -0
- package/lib/SchemaUtils.js.map +1 -0
- package/lib/json-schema/Constants.d.ts +2 -0
- package/lib/json-schema/Constants.js +7 -0
- package/lib/json-schema/Constants.js.map +1 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.d.ts +40 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js +4 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js.map +1 -0
- package/lib/json-schema/IJsonSchemaSerializer.d.ts +7 -0
- package/lib/json-schema/IJsonSchemaSerializer.js +4 -0
- package/lib/json-schema/IJsonSchemaSerializer.js.map +1 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.d.ts +41 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js +4 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js.map +1 -0
- package/lib/json-schema/IJsonSchemaUnserializer.d.ts +5 -0
- package/lib/json-schema/IJsonSchemaUnserializer.js +4 -0
- package/lib/json-schema/IJsonSchemaUnserializer.js.map +1 -0
- package/lib/json-schema/IParseOptions.d.ts +16 -0
- package/lib/json-schema/IParseOptions.js +6 -0
- package/lib/json-schema/IParseOptions.js.map +1 -0
- package/lib/json-schema/JsonSchema.d.ts +22 -0
- package/lib/json-schema/JsonSchema.js +109 -0
- package/lib/json-schema/JsonSchema.js.map +1 -0
- package/lib/json-schema/JsonSchema7.d.ts +16 -0
- package/lib/json-schema/JsonSchema7.js +22 -0
- package/lib/json-schema/JsonSchema7.js.map +1 -0
- package/lib/json-schema/JsonSchema7Serializer.d.ts +42 -0
- package/lib/json-schema/JsonSchema7Serializer.js +438 -0
- package/lib/json-schema/JsonSchema7Serializer.js.map +1 -0
- package/lib/json-schema/JsonSchema7Unserializer.d.ts +60 -0
- package/lib/json-schema/JsonSchema7Unserializer.js +499 -0
- package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -0
- package/lib/options/IAbstractOptions.d.ts +19 -0
- package/lib/options/IAbstractOptions.js +4 -0
- package/lib/options/IAbstractOptions.js.map +1 -0
- package/lib/options/IAttributeOptions.d.ts +7 -0
- package/lib/options/IAttributeOptions.js +4 -0
- package/lib/options/IAttributeOptions.js.map +1 -0
- package/lib/options/IEntityOptions.d.ts +4 -0
- package/lib/options/IEntityOptions.js +4 -0
- package/lib/options/IEntityOptions.js.map +1 -0
- package/lib/options/IObjectOptions.d.ts +4 -0
- package/lib/options/IObjectOptions.js +4 -0
- package/lib/options/IObjectOptions.js.map +1 -0
- package/lib/options/IPropertyOptions.d.ts +24 -0
- package/lib/options/IPropertyOptions.js +4 -0
- package/lib/options/IPropertyOptions.js.map +1 -0
- package/lib/options/ISchemaOptions.d.ts +4 -0
- package/lib/options/ISchemaOptions.js +4 -0
- package/lib/options/ISchemaOptions.js.map +1 -0
- package/lib/registry/AbstractRegistry.d.ts +91 -0
- package/lib/registry/AbstractRegistry.js +135 -0
- package/lib/registry/AbstractRegistry.js.map +1 -0
- package/lib/registry/Binding.d.ts +9 -0
- package/lib/registry/Binding.js +17 -0
- package/lib/registry/Binding.js.map +1 -0
- package/lib/registry/DefaultEntityRef.d.ts +30 -0
- package/lib/registry/DefaultEntityRef.js +60 -0
- package/lib/registry/DefaultEntityRef.js.map +1 -0
- package/lib/registry/DefaultNamespacedRegistry.d.ts +153 -0
- package/lib/registry/DefaultNamespacedRegistry.js +511 -0
- package/lib/registry/DefaultNamespacedRegistry.js.map +1 -0
- package/lib/registry/DefaultPropertyRef.d.ts +44 -0
- package/lib/registry/DefaultPropertyRef.js +175 -0
- package/lib/registry/DefaultPropertyRef.js.map +1 -0
- package/lib/registry/MetadataRegistry.d.ts +52 -0
- package/lib/registry/MetadataRegistry.js +186 -0
- package/lib/registry/MetadataRegistry.js.map +1 -0
- package/lib/registry/RegistryFactory.d.ts +43 -0
- package/lib/registry/RegistryFactory.js +109 -0
- package/lib/registry/RegistryFactory.js.map +1 -0
- package/lib/serializer/ISerializeOptions.d.ts +10 -0
- package/lib/serializer/ISerializeOptions.js +4 -0
- package/lib/serializer/ISerializeOptions.js.map +1 -0
- package/lib/serializer/ISerializer.d.ts +5 -0
- package/lib/serializer/ISerializer.js +4 -0
- package/lib/serializer/ISerializer.js.map +1 -0
- package/lib/serializer/ISerializerFactory.d.ts +13 -0
- package/lib/serializer/ISerializerFactory.js +4 -0
- package/lib/serializer/ISerializerFactory.js.map +1 -0
- package/lib/serializer/IUnserializeOptions.d.ts +14 -0
- package/lib/serializer/IUnserializeOptions.js +4 -0
- package/lib/serializer/IUnserializeOptions.js.map +1 -0
- package/lib/serializer/IUnserializer.d.ts +5 -0
- package/lib/serializer/IUnserializer.js +4 -0
- package/lib/serializer/IUnserializer.js.map +1 -0
- package/lib/serializer/SerializerRegistry.d.ts +8 -0
- package/lib/serializer/SerializerRegistry.js +20 -0
- package/lib/serializer/SerializerRegistry.js.map +1 -0
- package/lib/validation/DefaultValidator.d.ts +14 -0
- package/lib/validation/DefaultValidator.js +221 -0
- package/lib/validation/DefaultValidator.js.map +1 -0
- package/lib/validation/IValidateOptions.d.ts +4 -0
- package/lib/validation/IValidateOptions.js +4 -0
- package/lib/validation/IValidateOptions.js.map +1 -0
- package/lib/validation/IValidationError.d.ts +10 -0
- package/lib/validation/IValidationError.js +4 -0
- package/lib/validation/IValidationError.js.map +1 -0
- package/lib/validation/IValidationMessage.d.ts +4 -0
- package/lib/validation/IValidationMessage.js +4 -0
- package/lib/validation/IValidationMessage.js.map +1 -0
- package/lib/validation/IValidationOptions.d.ts +1 -0
- package/lib/validation/IValidationOptions.js +30 -0
- package/lib/validation/IValidationOptions.js.map +1 -0
- package/lib/validation/IValidationResult.d.ts +7 -0
- package/lib/validation/IValidationResult.js +4 -0
- package/lib/validation/IValidationResult.js.map +1 -0
- package/lib/validation/IValidator.d.ts +9 -0
- package/lib/validation/IValidator.js +4 -0
- package/lib/validation/IValidator.js.map +1 -0
- package/lib/validation/IValidatorEntry.d.ts +7 -0
- package/lib/validation/IValidatorEntry.js +4 -0
- package/lib/validation/IValidatorEntry.js.map +1 -0
- package/lib/validation/IValidatorHandle.d.ts +2 -0
- package/lib/validation/IValidatorHandle.js +4 -0
- package/lib/validation/IValidatorHandle.js.map +1 -0
- package/lib/validation/Validator.d.ts +17 -0
- package/lib/validation/Validator.js +54 -0
- package/lib/validation/Validator.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsNotEmpty = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper");
|
|
6
|
+
const DefaultValidator_1 = require("../../lib/validation/DefaultValidator");
|
|
7
|
+
function IsNotEmpty(options) {
|
|
8
|
+
return function (source, propertyName) {
|
|
9
|
+
const opts = {
|
|
10
|
+
validate: 'isNotEmpty'
|
|
11
|
+
};
|
|
12
|
+
if (options) {
|
|
13
|
+
lodash_1.assign(opts, { validateOptions: { isNotEmpty: {} } });
|
|
14
|
+
lodash_1.assign(opts.validateOptions.isNotEmpty, options);
|
|
15
|
+
}
|
|
16
|
+
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.IsNotEmpty = IsNotEmpty;
|
|
20
|
+
DefaultValidator_1.DefaultValidator.define({
|
|
21
|
+
name: 'isNotEmpty',
|
|
22
|
+
fn: (value, opts, instance) => {
|
|
23
|
+
let res = !(lodash_1.isUndefined(value) || lodash_1.isNull(value));
|
|
24
|
+
if (res) {
|
|
25
|
+
if (lodash_1.isString(value) || lodash_1.isArray(value)) {
|
|
26
|
+
return !lodash_1.isEmpty(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return res;
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: {
|
|
32
|
+
message: 'Property "%propertyName" must be set and be not empty.'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=IsNotEmpty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/IsNotEmpty.ts"],"names":[],"mappings":";;;AAAA,mCAA+E;AAC/E,mEAA8D;AAC9D,4EAAuE;AAOvE,SAAgB,UAAU,CAAC,OAA4B;IACrD,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,MAAM,IAAI,GAAQ;YAChB,QAAQ,EAAE,YAAY;SACvB,CAAC;QACF,IAAI,OAAO,EAAE;YACX,eAAM,CAAC,IAAI,EAAE,EAAC,eAAe,EAAE,EAAC,UAAU,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;YAClD,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SAClD;QAED,qCAAiB,CAAC,aAAa,CAC7B,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,gCAiBC;AAED,mCAAgB,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,CAAC,KAAU,EAAE,IAAyB,EAAE,QAAc,EAAE,EAAE;QAC5D,IAAI,GAAG,GAAG,CAAC,CAAC,oBAAW,CAAC,KAAK,CAAC,IAAI,eAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,IAAI,GAAG,EAAE;YACP,IAAI,iBAAQ,CAAC,KAAK,CAAC,IAAI,gBAAO,CAAC,KAAK,CAAC,EAAE;gBACrC,OAAO,CAAC,gBAAO,CAAC,KAAK,CAAC,CAAC;aACxB;SACF;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,wDAAwD;KAClE;CACF,CACF,CAAC","file":"IsNotEmpty.js","sourcesContent":["import {assign, isArray, isEmpty, isNull, isString, isUndefined} from 'lodash';\nimport {AnnotationsHelper} from '../../lib/AnnotationsHelper';\nimport {DefaultValidator} from '../../lib/validation/DefaultValidator';\nimport {IValidateOptions} from '../../lib/validation/IValidateOptions';\n\nexport interface IIsNotEmptyOptions extends IValidateOptions {\n message?: string\n}\n\nexport function IsNotEmpty(options?: IIsNotEmptyOptions) {\n return function (source: any, propertyName: string) {\n const opts: any = {\n validate: 'isNotEmpty'\n };\n if (options) {\n assign(opts, {validateOptions: {isNotEmpty: {}}});\n assign(opts.validateOptions.isNotEmpty, options);\n }\n\n AnnotationsHelper.forPropertyOn(\n source.constructor,\n propertyName,\n opts,\n 'merge'\n );\n };\n}\n\nDefaultValidator.define({\n name: 'isNotEmpty',\n fn: (value: any, opts?: IIsNotEmptyOptions, instance?: any) => {\n let res = !(isUndefined(value) || isNull(value));\n if (res) {\n if (isString(value) || isArray(value)) {\n return !isEmpty(value);\n }\n }\n return res;\n },\n defaultOptions: {\n message: 'Property \"%propertyName\" must be set and be not empty.'\n }\n }\n);\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IValidateOptions } from '../../lib/validation/IValidateOptions';
|
|
2
|
+
export interface IMaxLengthOptions extends IValidateOptions {
|
|
3
|
+
maxLength?: number;
|
|
4
|
+
message?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function MaxLength(value: number, options?: IMaxLengthOptions): (source: any, propertyName: string) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaxLength = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper");
|
|
6
|
+
const DefaultValidator_1 = require("../../lib/validation/DefaultValidator");
|
|
7
|
+
function MaxLength(value, options) {
|
|
8
|
+
return function (source, propertyName) {
|
|
9
|
+
const opts = {
|
|
10
|
+
maxLength: value
|
|
11
|
+
};
|
|
12
|
+
if (options) {
|
|
13
|
+
lodash_1.assign(opts, { validateOptions: { maxLength: {} } });
|
|
14
|
+
lodash_1.assign(opts.validateOptions.maxLength, options);
|
|
15
|
+
}
|
|
16
|
+
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.MaxLength = MaxLength;
|
|
20
|
+
DefaultValidator_1.DefaultValidator.define({
|
|
21
|
+
name: 'maxLength',
|
|
22
|
+
fn: (value, opts, instance) => {
|
|
23
|
+
if (lodash_1.isString(value)) {
|
|
24
|
+
return value.length <= opts.maxLength;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
},
|
|
28
|
+
defaultOptions: {
|
|
29
|
+
message: 'Length of property "%propertyName" must be greeter then %options.maxLength.'
|
|
30
|
+
},
|
|
31
|
+
involveOnOptionKey: 'maxLength'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=MaxLength.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/MaxLength.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC,mEAA8D;AAC9D,4EAAuE;AAQvE,SAAgB,SAAS,CAAC,KAAa,EAAE,OAA2B;IAClE,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,MAAM,IAAI,GAAQ;YAChB,SAAS,EAAE,KAAK;SACjB,CAAC;QACF,IAAI,OAAO,EAAE;YACX,eAAM,CAAC,IAAI,EAAE,EAAC,eAAe,EAAE,EAAC,SAAS,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;YACjD,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SACjD;QAED,qCAAiB,CAAC,aAAa,CAC7B,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,8BAiBC;AAED,mCAAgB,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW;IACjB,EAAE,EAAE,CAAC,KAAa,EAAE,IAAwB,EAAE,QAAc,EAAE,EAAE;QAC9D,IAAI,iBAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC;SACvC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,6EAA6E;KACvF;IACD,kBAAkB,EAAE,WAAW;CAChC,CACF,CAAC","file":"MaxLength.js","sourcesContent":["import {assign, isString} from 'lodash';\n\nimport {AnnotationsHelper} from '../../lib/AnnotationsHelper';\nimport {DefaultValidator} from '../../lib/validation/DefaultValidator';\nimport {IValidateOptions} from '../../lib/validation/IValidateOptions';\n\nexport interface IMaxLengthOptions extends IValidateOptions {\n maxLength?: number,\n message?: string\n}\n\nexport function MaxLength(value: number, options?: IMaxLengthOptions) {\n return function (source: any, propertyName: string) {\n const opts: any = {\n maxLength: value\n };\n if (options) {\n assign(opts, {validateOptions: {maxLength: {}}});\n assign(opts.validateOptions.maxLength, options);\n }\n\n AnnotationsHelper.forPropertyOn(\n source.constructor,\n propertyName,\n opts,\n 'merge'\n );\n };\n}\n\nDefaultValidator.define({\n name: 'maxLength',\n fn: (value: string, opts?: IMaxLengthOptions, instance?: any) => {\n if (isString(value)) {\n return value.length <= opts.maxLength;\n }\n return false;\n },\n defaultOptions: {\n message: 'Length of property \"%propertyName\" must be greeter then %options.maxLength.'\n },\n involveOnOptionKey: 'maxLength'\n }\n);\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IValidateOptions } from '../../lib/validation/IValidateOptions';
|
|
2
|
+
export interface IMinLengthOptions extends IValidateOptions {
|
|
3
|
+
minLength?: number;
|
|
4
|
+
message?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function MinLength(value: number, options?: IMinLengthOptions): (source: any, propertyName: string) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MinLength = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper");
|
|
6
|
+
const DefaultValidator_1 = require("../../lib/validation/DefaultValidator");
|
|
7
|
+
function MinLength(value, options) {
|
|
8
|
+
return function (source, propertyName) {
|
|
9
|
+
const opts = {
|
|
10
|
+
minLength: value
|
|
11
|
+
};
|
|
12
|
+
if (options) {
|
|
13
|
+
lodash_1.assign(opts, { validateOptions: { minLength: {} } });
|
|
14
|
+
lodash_1.assign(opts.validateOptions.minLength, options);
|
|
15
|
+
}
|
|
16
|
+
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.MinLength = MinLength;
|
|
20
|
+
DefaultValidator_1.DefaultValidator.define({
|
|
21
|
+
name: 'minLength',
|
|
22
|
+
fn: (value, opts, instance) => {
|
|
23
|
+
if (lodash_1.isString(value)) {
|
|
24
|
+
return value.length >= opts.minLength;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
},
|
|
28
|
+
defaultOptions: {
|
|
29
|
+
message: 'Length of property "%propertyName" must be greeter then %options.minLength.'
|
|
30
|
+
},
|
|
31
|
+
involveOnOptionKey: 'minLength'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=MinLength.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/MinLength.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC,mEAA8D;AAC9D,4EAAuE;AAQvE,SAAgB,SAAS,CAAC,KAAa,EAAE,OAA2B;IAClE,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,MAAM,IAAI,GAAQ;YAChB,SAAS,EAAE,KAAK;SACjB,CAAC;QACF,IAAI,OAAO,EAAE;YACX,eAAM,CAAC,IAAI,EAAE,EAAC,eAAe,EAAE,EAAC,SAAS,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;YACjD,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SACjD;QAED,qCAAiB,CAAC,aAAa,CAC7B,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,8BAiBC;AAED,mCAAgB,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW;IACjB,EAAE,EAAE,CAAC,KAAa,EAAE,IAAwB,EAAE,QAAc,EAAE,EAAE;QAC9D,IAAI,iBAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC;SACvC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,6EAA6E;KACvF;IACD,kBAAkB,EAAE,WAAW;CAChC,CACF,CAAC","file":"MinLength.js","sourcesContent":["import {assign, isString} from 'lodash';\n\nimport {AnnotationsHelper} from '../../lib/AnnotationsHelper';\nimport {DefaultValidator} from '../../lib/validation/DefaultValidator';\nimport {IValidateOptions} from '../../lib/validation/IValidateOptions';\n\nexport interface IMinLengthOptions extends IValidateOptions {\n minLength?: number,\n message?: string\n}\n\nexport function MinLength(value: number, options?: IMinLengthOptions) {\n return function (source: any, propertyName: string) {\n const opts: any = {\n minLength: value\n };\n if (options) {\n assign(opts, {validateOptions: {minLength: {}}});\n assign(opts.validateOptions.minLength, options);\n }\n\n AnnotationsHelper.forPropertyOn(\n source.constructor,\n propertyName,\n opts,\n 'merge'\n );\n };\n}\n\nDefaultValidator.define({\n name: 'minLength',\n fn: (value: string, opts?: IMinLengthOptions, instance?: any) => {\n if (isString(value)) {\n return value.length >= opts.minLength;\n }\n return false;\n },\n defaultOptions: {\n message: 'Length of property \"%propertyName\" must be greeter then %options.minLength.'\n },\n involveOnOptionKey: 'minLength'\n }\n);\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IValidateOptions } from '../../lib/validation/IValidateOptions';
|
|
2
|
+
export interface IRegexOptions extends IValidateOptions {
|
|
3
|
+
pattern?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
flags?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function Regex(regex: string | RegExp, options?: IRegexOptions): (source: any, propertyName: string) => void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Regex = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper");
|
|
6
|
+
const DefaultValidator_1 = require("../../lib/validation/DefaultValidator");
|
|
7
|
+
function Regex(regex, options) {
|
|
8
|
+
return function (source, propertyName) {
|
|
9
|
+
const opts = {
|
|
10
|
+
pattern: lodash_1.isString(regex) ? regex : regex.source,
|
|
11
|
+
};
|
|
12
|
+
if (!lodash_1.isString(regex) && !lodash_1.isEmpty(regex.flags)) {
|
|
13
|
+
opts.validateOptions = {
|
|
14
|
+
regex: {
|
|
15
|
+
flags: regex.flags,
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (options) {
|
|
20
|
+
lodash_1.assign(opts.validateOptions.regex, options);
|
|
21
|
+
}
|
|
22
|
+
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.Regex = Regex;
|
|
26
|
+
DefaultValidator_1.DefaultValidator.define({
|
|
27
|
+
name: 'regex',
|
|
28
|
+
fn: (value, options, instance) => {
|
|
29
|
+
// if (isUndefined(value) || isNull(value)) {
|
|
30
|
+
// return true;
|
|
31
|
+
// }
|
|
32
|
+
if (lodash_1.isString(value)) {
|
|
33
|
+
const r = new RegExp(options.pattern, options.flags);
|
|
34
|
+
if (r.test(value)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
defaultOptions: {
|
|
41
|
+
message: 'Value of property "%propertyName" doesn\'t match the regular expression "%options.pattern".'
|
|
42
|
+
},
|
|
43
|
+
involveOnOptionKey: 'pattern'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=Regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/Regex.ts"],"names":[],"mappings":";;;AAAA,mCAAsE;AAEtE,mEAA8D;AAC9D,4EAAuE;AASvE,SAAgB,KAAK,CAAC,KAAsB,EAAE,OAAuB;IACnE,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,MAAM,IAAI,GAAQ;YAChB,OAAO,EAAE,iBAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;SAChD,CAAC;QACF,IAAI,CAAC,iBAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC7C,IAAI,CAAC,eAAe,GAAG;gBACrB,KAAK,EAAE;oBACL,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB;aACF,CAAC;SACH;QACD,IAAI,OAAO,EAAE;YACX,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SAC7C;QAED,qCAAiB,CAAC,aAAa,CAC7B,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAvBD,sBAuBC;AAED,mCAAgB,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO;IACb,EAAE,EAAE,CAAC,KAAa,EAAE,OAAsB,EAAE,QAAc,EAAE,EAAE;QAC5D,6CAA6C;QAC7C,iBAAiB;QACjB,IAAI;QACJ,IAAI,iBAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACrD,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBACjB,OAAO,IAAI,CAAC;aACb;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,6FAA6F;KACvG;IACD,kBAAkB,EAAE,SAAS;CAC9B,CACF,CAAC","file":"Regex.js","sourcesContent":["import {assign, isEmpty, isNull, isString, isUndefined} from 'lodash';\n\nimport {AnnotationsHelper} from '../../lib/AnnotationsHelper';\nimport {DefaultValidator} from '../../lib/validation/DefaultValidator';\nimport {IValidateOptions} from '../../lib/validation/IValidateOptions';\n\nexport interface IRegexOptions extends IValidateOptions {\n pattern?: string;\n message?: string;\n flags?: string;\n}\n\nexport function Regex(regex: string | RegExp, options?: IRegexOptions) {\n return function (source: any, propertyName: string) {\n const opts: any = {\n pattern: isString(regex) ? regex : regex.source,\n };\n if (!isString(regex) && !isEmpty(regex.flags)) {\n opts.validateOptions = {\n regex: {\n flags: regex.flags,\n }\n };\n }\n if (options) {\n assign(opts.validateOptions.regex, options);\n }\n\n AnnotationsHelper.forPropertyOn(\n source.constructor,\n propertyName,\n opts,\n 'merge'\n );\n };\n}\n\nDefaultValidator.define({\n name: 'regex',\n fn: (value: string, options: IRegexOptions, instance?: any) => {\n // if (isUndefined(value) || isNull(value)) {\n // return true;\n // }\n if (isString(value)) {\n const r = new RegExp(options.pattern, options.flags);\n if (r.test(value)) {\n return true;\n }\n }\n return false;\n },\n defaultOptions: {\n message: 'Value of property \"%propertyName\" doesn\\'t match the regular expression \"%options.pattern\".'\n },\n involveOnOptionKey: 'pattern'\n }\n);\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Required = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper");
|
|
6
|
+
const DefaultValidator_1 = require("../../lib/validation/DefaultValidator");
|
|
7
|
+
function Required(options) {
|
|
8
|
+
return function (source, propertyName) {
|
|
9
|
+
const opts = {
|
|
10
|
+
required: true
|
|
11
|
+
};
|
|
12
|
+
if (options) {
|
|
13
|
+
lodash_1.assign(opts, { validateOptions: { required: {} } });
|
|
14
|
+
lodash_1.assign(opts.validateOptions.required, options);
|
|
15
|
+
}
|
|
16
|
+
AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge');
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.Required = Required;
|
|
20
|
+
DefaultValidator_1.DefaultValidator.define({
|
|
21
|
+
name: 'required',
|
|
22
|
+
fn: (value, opts, instance) => {
|
|
23
|
+
if (lodash_1.isUndefined(value) || lodash_1.isNull(value)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
defaultOptions: {
|
|
29
|
+
message: 'Property "%propertyName" is required.'
|
|
30
|
+
},
|
|
31
|
+
involveOnOptionKey: 'required'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=Required.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/Required.ts"],"names":[],"mappings":";;;AAAA,mCAAmD;AAEnD,mEAA8D;AAC9D,4EAAuE;AAOvE,SAAgB,QAAQ,CAAC,OAA0B;IACjD,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,MAAM,IAAI,GAAQ;YAChB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,IAAI,OAAO,EAAE;YACX,eAAM,CAAC,IAAI,EAAE,EAAC,eAAe,EAAE,EAAC,QAAQ,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;YAChD,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SAChD;QAED,qCAAiB,CAAC,aAAa,CAC7B,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAjBD,4BAiBC;AAED,mCAAgB,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,UAAU;IAChB,EAAE,EAAE,CAAC,KAAa,EAAE,IAAuB,EAAE,QAAc,EAAE,EAAE;QAC7D,IAAI,oBAAW,CAAC,KAAK,CAAC,IAAI,eAAM,CAAC,KAAK,CAAC,EAAE;YACvC,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,cAAc,EAAE;QACd,OAAO,EAAE,uCAAuC;KACjD;IACD,kBAAkB,EAAE,UAAU;CAC/B,CACF,CAAC","file":"Required.js","sourcesContent":["import {assign, isNull, isUndefined} from 'lodash';\n\nimport {AnnotationsHelper} from '../../lib/AnnotationsHelper';\nimport {DefaultValidator} from '../../lib/validation/DefaultValidator';\nimport {IValidateOptions} from '../../lib/validation/IValidateOptions';\n\nexport interface IRequiredOptions extends IValidateOptions {\n message?: string\n}\n\nexport function Required(options?: IRequiredOptions) {\n return function (source: any, propertyName: string) {\n const opts: any = {\n required: true\n };\n if (options) {\n assign(opts, {validateOptions: {required: {}}});\n assign(opts.validateOptions.required, options);\n }\n\n AnnotationsHelper.forPropertyOn(\n source.constructor,\n propertyName,\n opts,\n 'merge'\n );\n };\n}\n\nDefaultValidator.define({\n name: 'required',\n fn: (value: string, opts?: IRequiredOptions, instance?: any) => {\n if (isUndefined(value) || isNull(value)) {\n return false;\n }\n return true;\n },\n defaultOptions: {\n message: 'Property \"%propertyName\" is required.'\n },\n involveOnOptionKey: 'required'\n }\n);\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IsEmail } from './IsEmail';
|
|
2
|
+
import { Regex } from './Regex';
|
|
3
|
+
import { Required } from './Required';
|
|
4
|
+
import { Hostname } from './Hostname';
|
|
5
|
+
import { Ip4 } from './Ip4';
|
|
6
|
+
import { Ip6 } from './Ip6';
|
|
7
|
+
import { MinLength } from './MinLength';
|
|
8
|
+
import { MaxLength } from './MaxLength';
|
|
9
|
+
export { IsEmail, Regex, Required, Hostname, Ip4, Ip6, MinLength, MaxLength };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaxLength = exports.MinLength = exports.Ip6 = exports.Ip4 = exports.Hostname = exports.Required = exports.Regex = exports.IsEmail = void 0;
|
|
4
|
+
const IsEmail_1 = require("./IsEmail");
|
|
5
|
+
Object.defineProperty(exports, "IsEmail", { enumerable: true, get: function () { return IsEmail_1.IsEmail; } });
|
|
6
|
+
const Regex_1 = require("./Regex");
|
|
7
|
+
Object.defineProperty(exports, "Regex", { enumerable: true, get: function () { return Regex_1.Regex; } });
|
|
8
|
+
const Required_1 = require("./Required");
|
|
9
|
+
Object.defineProperty(exports, "Required", { enumerable: true, get: function () { return Required_1.Required; } });
|
|
10
|
+
const Hostname_1 = require("./Hostname");
|
|
11
|
+
Object.defineProperty(exports, "Hostname", { enumerable: true, get: function () { return Hostname_1.Hostname; } });
|
|
12
|
+
const Ip4_1 = require("./Ip4");
|
|
13
|
+
Object.defineProperty(exports, "Ip4", { enumerable: true, get: function () { return Ip4_1.Ip4; } });
|
|
14
|
+
const Ip6_1 = require("./Ip6");
|
|
15
|
+
Object.defineProperty(exports, "Ip6", { enumerable: true, get: function () { return Ip6_1.Ip6; } });
|
|
16
|
+
const MinLength_1 = require("./MinLength");
|
|
17
|
+
Object.defineProperty(exports, "MinLength", { enumerable: true, get: function () { return MinLength_1.MinLength; } });
|
|
18
|
+
const MaxLength_1 = require("./MaxLength");
|
|
19
|
+
Object.defineProperty(exports, "MaxLength", { enumerable: true, get: function () { return MaxLength_1.MaxLength; } });
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/decorators/validate/index.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAU1B,wFAVA,iBAAO,OAUA;AATf,mCAA8B;AASb,sFATT,aAAK,OASS;AARtB,yCAAoC;AAQZ,yFARhB,mBAAQ,OAQgB;AAPhC,yCAAoC;AAOF,yFAP1B,mBAAQ,OAO0B;AAN1C,+BAA0B;AAMkB,oFANpC,SAAG,OAMoC;AAL/C,+BAA0B;AAKuB,oFALzC,SAAG,OAKyC;AAJpD,2CAAsC;AAIgB,0FAJ9C,qBAAS,OAI8C;AAH/D,2CAAsC;AAG2B,0FAHzD,qBAAS,OAGyD","file":"index.js","sourcesContent":["import {IsEmail} from './IsEmail';\nimport {Regex} from './Regex';\nimport {Required} from './Required';\nimport {Hostname} from './Hostname';\nimport {Ip4} from './Ip4';\nimport {Ip6} from './Ip6';\nimport {MinLength} from './MinLength';\nimport {MaxLength} from './MaxLength';\n\n\nexport {IsEmail, Regex, Required, Hostname, Ip4, Ip6, MinLength, MaxLength};\n"],"sourceRoot":"../.."}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './browser';
|
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./browser"), exports);
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B","file":"index.js","sourcesContent":["export * from './browser';\n"],"sourceRoot":"."}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { METADATA_TYPE } from './Constants';
|
|
2
|
+
import { IBaseRef } from '../api/IBaseRef';
|
|
3
|
+
import { IClassRef } from '../api/IClassRef';
|
|
4
|
+
import { ILookupRegistry } from '../api/ILookupRegistry';
|
|
5
|
+
export declare abstract class AbstractRef implements IBaseRef {
|
|
6
|
+
readonly metaType: METADATA_TYPE;
|
|
7
|
+
namespace: string;
|
|
8
|
+
private _cachedOptions;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly object: IClassRef;
|
|
11
|
+
constructor(type: METADATA_TYPE, name: string, object?: IClassRef | Function | string, namespace?: string);
|
|
12
|
+
abstract getClassRefFor(object: string | Function | IClassRef, type: METADATA_TYPE): IClassRef;
|
|
13
|
+
getNamespace(): string;
|
|
14
|
+
abstract getRegistry(): ILookupRegistry;
|
|
15
|
+
getSourceRef(): IClassRef;
|
|
16
|
+
protected getOptionsEntry(): any;
|
|
17
|
+
getOptions(key?: string, defaultValue?: any): any;
|
|
18
|
+
setOptions(options: any): void;
|
|
19
|
+
setOption(key: string, value: any): void;
|
|
20
|
+
hasOption(key: string): boolean;
|
|
21
|
+
getClassRef(): IClassRef;
|
|
22
|
+
getClass(create?: boolean): Function;
|
|
23
|
+
get machineName(): string;
|
|
24
|
+
get storingName(): any;
|
|
25
|
+
abstract id(): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractRef = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const Constants_1 = require("./Constants");
|
|
6
|
+
const IClassRef_1 = require("../api/IClassRef");
|
|
7
|
+
const MetadataRegistry_1 = require("./registry/MetadataRegistry");
|
|
8
|
+
class AbstractRef {
|
|
9
|
+
constructor(type, name, object = null, namespace = Constants_1.DEFAULT_NAMESPACE) {
|
|
10
|
+
this.namespace = Constants_1.DEFAULT_NAMESPACE;
|
|
11
|
+
this.namespace = namespace;
|
|
12
|
+
this.metaType = type;
|
|
13
|
+
this.name = name;
|
|
14
|
+
if (IClassRef_1.isClassRef(object)) {
|
|
15
|
+
this.object = object;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.object = object ? this.getClassRefFor(object, type) : null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getNamespace() {
|
|
22
|
+
return this.namespace;
|
|
23
|
+
}
|
|
24
|
+
getSourceRef() {
|
|
25
|
+
return this.object;
|
|
26
|
+
}
|
|
27
|
+
getOptionsEntry() {
|
|
28
|
+
if (!this._cachedOptions) {
|
|
29
|
+
if (this.metaType === Constants_1.METATYPE_PROPERTY) {
|
|
30
|
+
this._cachedOptions = MetadataRegistry_1.MetadataRegistry.$().findCached(this.metaType, (x) => x.target === this.getClass(true) &&
|
|
31
|
+
x.propertyName === this.name &&
|
|
32
|
+
x.namespace === this.getNamespace());
|
|
33
|
+
if (!this._cachedOptions) {
|
|
34
|
+
this._cachedOptions = { target: this.getClass(true), propertyName: this.name, namespace: this.getNamespace() };
|
|
35
|
+
MetadataRegistry_1.MetadataRegistry.$().addCached(this.metaType, this._cachedOptions);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (this.metaType === Constants_1.METATYPE_SCHEMA) {
|
|
39
|
+
this._cachedOptions = MetadataRegistry_1.MetadataRegistry.$().findCached(this.metaType, (x) => x.name === this.name &&
|
|
40
|
+
x.namespace === this.getNamespace());
|
|
41
|
+
if (!this._cachedOptions) {
|
|
42
|
+
this._cachedOptions = { name: this.name, namespace: this.getNamespace() };
|
|
43
|
+
MetadataRegistry_1.MetadataRegistry.$().addCached(this.metaType, this._cachedOptions);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this._cachedOptions = MetadataRegistry_1.MetadataRegistry.$().findCached(this.metaType, (x) => x.target === this.getClass(true) &&
|
|
48
|
+
x.namespace === this.getNamespace());
|
|
49
|
+
if (!this._cachedOptions) {
|
|
50
|
+
this._cachedOptions = { target: this.getClass(true), namespace: this.getNamespace() };
|
|
51
|
+
MetadataRegistry_1.MetadataRegistry.$().addCached(this.metaType, this._cachedOptions);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return this._cachedOptions;
|
|
56
|
+
}
|
|
57
|
+
getOptions(key, defaultValue = null) {
|
|
58
|
+
if (key) {
|
|
59
|
+
return lodash_1.get(this.getOptionsEntry(), key, defaultValue);
|
|
60
|
+
}
|
|
61
|
+
return this.getOptionsEntry();
|
|
62
|
+
}
|
|
63
|
+
setOptions(options) {
|
|
64
|
+
if (options && !lodash_1.isEmpty(lodash_1.keys(options))) {
|
|
65
|
+
const opts = this.getOptionsEntry();
|
|
66
|
+
// if same object cause taken from MetadataRegistry then ignore setting
|
|
67
|
+
if (opts !== options) {
|
|
68
|
+
for (const k of lodash_1.keys(opts)) {
|
|
69
|
+
delete opts[k];
|
|
70
|
+
}
|
|
71
|
+
lodash_1.assign(opts, options);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
setOption(key, value) {
|
|
76
|
+
const opts = this.getOptionsEntry();
|
|
77
|
+
lodash_1.set(opts, key, value);
|
|
78
|
+
}
|
|
79
|
+
hasOption(key) {
|
|
80
|
+
const opts = this.getOptionsEntry();
|
|
81
|
+
return lodash_1.has(opts, key);
|
|
82
|
+
}
|
|
83
|
+
// getOptions(key: string = null, defaultValue: any = null): any | OPTS {
|
|
84
|
+
// if (key) {
|
|
85
|
+
// return get(this.options, key, defaultValue);
|
|
86
|
+
// }
|
|
87
|
+
// return this.options;
|
|
88
|
+
// }
|
|
89
|
+
//
|
|
90
|
+
// setOptions(opts: any) {
|
|
91
|
+
// if (opts && !isEmpty(keys(opts))) {
|
|
92
|
+
// if (!isEmpty(keys(this.options))) {
|
|
93
|
+
// this.options = merge(this.options, opts);
|
|
94
|
+
// } else {
|
|
95
|
+
// this.options = opts;
|
|
96
|
+
// }
|
|
97
|
+
// }
|
|
98
|
+
// }
|
|
99
|
+
//
|
|
100
|
+
//
|
|
101
|
+
// setOption(key: string, value: any) {
|
|
102
|
+
// if (!this.options) {
|
|
103
|
+
// this.options = <any>{};
|
|
104
|
+
// }
|
|
105
|
+
// set(<any>this.options, key, value);
|
|
106
|
+
// }
|
|
107
|
+
getClassRef() {
|
|
108
|
+
return this.object;
|
|
109
|
+
}
|
|
110
|
+
getClass(create = false) {
|
|
111
|
+
return this.getClassRef().getClass(create);
|
|
112
|
+
}
|
|
113
|
+
get machineName() {
|
|
114
|
+
return lodash_1.snakeCase(this.name);
|
|
115
|
+
}
|
|
116
|
+
get storingName() {
|
|
117
|
+
let name = this.getOptions('name');
|
|
118
|
+
if (!name) {
|
|
119
|
+
name = lodash_1.snakeCase(this.name);
|
|
120
|
+
}
|
|
121
|
+
return name;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.AbstractRef = AbstractRef;
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=AbstractRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/AbstractRef.ts"],"names":[],"mappings":";;;AAAA,mCAAuE;AACvE,2CAAkG;AAElG,gDAAuD;AACvD,kEAA6D;AAI7D,MAAsB,WAAW;IAa/B,YAAY,IAAmB,EACnB,IAAY,EACZ,SAAwC,IAAI,EAC5C,YAAoB,6BAAiB;QAZjD,cAAS,GAAW,6BAAiB,CAAC;QAapC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,sBAAU,CAAC,MAAM,CAAC,EAAE;YACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACtB;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;SACjE;IACH,CAAC;IAID,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAID,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAES,eAAe;QACvB,IAAI,CAAC,IAAI,CAAC,cAAc,EA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EFAULT_NAMESPACE, METADATA_TYPE, METATYPE_PROPERTY, METATYPE_SCHEMA,} from './Constants';\nimport {IBaseRef} from '../api/IBaseRef';\nimport {IClassRef, isClassRef} from '../api/IClassRef';\nimport {MetadataRegistry} from './registry/MetadataRegistry';\nimport {ILookupRegistry} from '../api/ILookupRegistry';\n\n\nexport abstract class AbstractRef implements IBaseRef {\n\n readonly metaType: METADATA_TYPE;\n\n namespace: string = DEFAULT_NAMESPACE;\n\n private _cachedOptions: any;\n\n readonly name: string;\n\n readonly object: IClassRef;\n\n\n constructor(type: METADATA_TYPE,\n name: string,\n object: IClassRef | Function | string = null,\n namespace: string = DEFAULT_NAMESPACE) {\n this.namespace = namespace;\n this.metaType = type;\n this.name = name;\n if (isClassRef(object)) {\n this.object = object;\n } else {\n this.object = object ? this.getClassRefFor(object, type) : null;\n }\n }\n\n abstract getClassRefFor(object: string | Function | IClassRef, type: METADATA_TYPE): IClassRef;\n\n getNamespace() {\n return this.namespace;\n }\n\n abstract getRegistry(): ILookupRegistry;\n\n getSourceRef() {\n return this.object;\n }\n\n protected getOptionsEntry() {\n if (!this._cachedOptions) {\n if (this.metaType === METATYPE_PROPERTY) {\n this._cachedOptions = MetadataRegistry.$().findCached(this.metaType, (x: any) =>\n x.target === this.getClass(true) &&\n x.propertyName === this.name &&\n x.namespace === this.getNamespace()\n );\n if (!this._cachedOptions) {\n this._cachedOptions = {target: this.getClass(true), propertyName: this.name, namespace: this.getNamespace()};\n MetadataRegistry.$().addCached(this.metaType, this._cachedOptions);\n }\n } else if (this.metaType === METATYPE_SCHEMA) {\n this._cachedOptions = MetadataRegistry.$().findCached(this.metaType, (x: any) =>\n x.name === this.name &&\n x.namespace === this.getNamespace()\n );\n if (!this._cachedOptions) {\n this._cachedOptions = {name: this.name, namespace: this.getNamespace()};\n MetadataRegistry.$().addCached(this.metaType, this._cachedOptions);\n }\n } else {\n this._cachedOptions = MetadataRegistry.$().findCached(this.metaType, (x: any) =>\n x.target === this.getClass(true) &&\n x.namespace === this.getNamespace()\n );\n if (!this._cachedOptions) {\n this._cachedOptions = {target: this.getClass(true), namespace: this.getNamespace()};\n MetadataRegistry.$().addCached(this.metaType, this._cachedOptions);\n }\n }\n }\n return this._cachedOptions;\n }\n\n getOptions(key?: string, defaultValue: any = null): any {\n if (key) {\n return get(this.getOptionsEntry(), key, defaultValue);\n }\n return this.getOptionsEntry();\n }\n\n setOptions(options: any) {\n if (options && !isEmpty(keys(options))) {\n const opts = this.getOptionsEntry();\n // if same object cause taken from MetadataRegistry then ignore setting\n if (opts !== options) {\n for (const k of keys(opts)) {\n delete opts[k];\n }\n assign(opts, options);\n }\n }\n }\n\n setOption(key: string, value: any) {\n const opts = this.getOptionsEntry();\n set(opts, key, value);\n }\n\n hasOption(key: string) {\n const opts = this.getOptionsEntry();\n return has(opts, key);\n }\n\n // getOptions(key: string = null, defaultValue: any = null): any | OPTS {\n // if (key) {\n // return get(this.options, key, defaultValue);\n // }\n // return this.options;\n // }\n //\n // setOptions(opts: any) {\n // if (opts && !isEmpty(keys(opts))) {\n // if (!isEmpty(keys(this.options))) {\n // this.options = merge(this.options, opts);\n // } else {\n // this.options = opts;\n // }\n // }\n // }\n //\n //\n // setOption(key: string, value: any) {\n // if (!this.options) {\n // this.options = <any>{};\n // }\n // set(<any>this.options, key, value);\n // }\n\n\n getClassRef() {\n return this.object;\n }\n\n\n getClass(create: boolean = false) {\n return this.getClassRef().getClass(create);\n }\n\n\n get machineName() {\n return snakeCase(this.name);\n }\n\n\n get storingName() {\n let name = this.getOptions('name');\n if (!name) {\n name = snakeCase(this.name);\n }\n\n return name;\n }\n\n\n abstract id(): string;\n\n\n // toJson() {\n // let options = cloneDeep(this.getOptions());\n // let o: any = {\n // id: this.id(),\n // name: this.name,\n // type: this.metaType,\n // machineName: this.machineName,\n // options: options\n // };\n // return o;\n // }\n\n}\n\n\n\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MERGE_TYPE } from './Constants';
|
|
2
|
+
import { IClassRef } from '../api/IClassRef';
|
|
3
|
+
export declare class AnnotationsHelper {
|
|
4
|
+
static forPropertyOn(object: Function, property: string, options: any, merge?: MERGE_TYPE): void;
|
|
5
|
+
static forEntityOn(object: Function, options: any, merge?: MERGE_TYPE): void;
|
|
6
|
+
static merge(classRef: IClassRef, options: any, property?: string): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnnotationsHelper = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const ClassRef_1 = require("./ClassRef");
|
|
6
|
+
const Constants_1 = require("./Constants");
|
|
7
|
+
const base_1 = require("@allgemein/base");
|
|
8
|
+
class AnnotationsHelper {
|
|
9
|
+
static forPropertyOn(object, property, options, merge) {
|
|
10
|
+
const source = base_1.ClassUtils.getFunction(object);
|
|
11
|
+
const classRefs = ClassRef_1.ClassRef.filter(c => c.getClass() === source);
|
|
12
|
+
for (const ref of classRefs) {
|
|
13
|
+
let prop = ref.getPropertyRef(property);
|
|
14
|
+
if (prop) {
|
|
15
|
+
const pOptions = prop.getOptions();
|
|
16
|
+
lodash_1.defaults(pOptions, options);
|
|
17
|
+
if (ref.hasEntityRef()) {
|
|
18
|
+
const eOptions = ref.getEntityRef().getOptions();
|
|
19
|
+
lodash_1.defaults(eOptions, options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
base_1.MetadataStorage.key(Constants_1.XS_ANNOTATION_OPTIONS_CACHE).push({
|
|
24
|
+
type: Constants_1.METATYPE_PROPERTY,
|
|
25
|
+
object: source,
|
|
26
|
+
property: property,
|
|
27
|
+
options: options,
|
|
28
|
+
merge: merge ? merge : 'default'
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static forEntityOn(object, options, merge) {
|
|
32
|
+
const source = base_1.ClassUtils.getFunction(object);
|
|
33
|
+
const classRefs = ClassRef_1.ClassRef.filter(c => c.getClass() === source);
|
|
34
|
+
for (const ref of classRefs) {
|
|
35
|
+
if (ref) {
|
|
36
|
+
let pOptions = ref.getOptions();
|
|
37
|
+
lodash_1.defaults(pOptions, options);
|
|
38
|
+
if (ref.hasEntityRef()) {
|
|
39
|
+
const eOptions = ref.getEntityRef().getOptions();
|
|
40
|
+
lodash_1.defaults(eOptions, options);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
base_1.MetadataStorage.key(Constants_1.XS_ANNOTATION_OPTIONS_CACHE).push({
|
|
45
|
+
type: Constants_1.METATYPE_ENTITY,
|
|
46
|
+
object: source,
|
|
47
|
+
options: options,
|
|
48
|
+
merge: merge
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static merge(classRef, options, property = null) {
|
|
52
|
+
if (!classRef) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const object = classRef.getClass(true);
|
|
56
|
+
const addOns = lodash_1.filter(base_1.MetadataStorage.key(Constants_1.XS_ANNOTATION_OPTIONS_CACHE), (x) => property ?
|
|
57
|
+
(classRef.isPlaceholder ? base_1.ClassUtils.getClassName(x.object) === classRef.name : x.object === object) &&
|
|
58
|
+
x.property === property &&
|
|
59
|
+
x.type == Constants_1.METATYPE_PROPERTY :
|
|
60
|
+
(classRef.isPlaceholder ? base_1.ClassUtils.getClassName(x.object) === classRef.name : x.object === object) &&
|
|
61
|
+
x.type == Constants_1.METATYPE_ENTITY);
|
|
62
|
+
if (addOns) {
|
|
63
|
+
addOns.forEach(addOn => {
|
|
64
|
+
const mergeType = lodash_1.get(addOn, 'merge', 'default');
|
|
65
|
+
switch (mergeType) {
|
|
66
|
+
case 'merge':
|
|
67
|
+
for (const k of lodash_1.keys(addOn.options)) {
|
|
68
|
+
if (lodash_1.isUndefined(options[k]) || lodash_1.isEmpty(options[k])) {
|
|
69
|
+
// create if not present
|
|
70
|
+
options[k] = addOn.options[k];
|
|
71
|
+
}
|
|
72
|
+
else if (lodash_1.isArray(options[k])) {
|
|
73
|
+
// add to array
|
|
74
|
+
options[k].push(addOn.options[k]);
|
|
75
|
+
}
|
|
76
|
+
else if (lodash_1.isObjectLike(options[k]) && lodash_1.isObjectLike(addOn.options[k])) {
|
|
77
|
+
lodash_1.merge(options[k], addOn.options[k]);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// create array
|
|
81
|
+
options[k] = [options[k], addOn.options[k]];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'assign':
|
|
86
|
+
lodash_1.assign(options, addOn.options);
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
lodash_1.defaults(options, addOn.options);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.AnnotationsHelper = AnnotationsHelper;
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=AnnotationsHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/AnnotationsHelper.ts"],"names":[],"mappings":";;;AAAA,mCAA+G;AAC/G,yCAAoC;AACpC,2CAAwG;AACxG,0CAA4D;AAK5D,MAAa,iBAAiB;IAE5B,MAAM,CAAC,aAAa,CAAC,MAAgB,EAAE,QAAgB,EAAE,OAAY,EAAE,KAAkB;QACvF,MAAM,MAAM,GAAG,iBAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAgB,mBAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,MAAM,CAAC,CAAC;QAE7E,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE;YAC3B,IAAI,IAAI,GAAG,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YACxC,IAAI,IAAI,EAAE;gBACR,MAAM,QAAQ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AC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,gBAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gCAClD,wBAAwB;gCACxB,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;6BAC/B;iCAAM,IAAI,gBAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gCAC9B,eAAe;gCACf,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;6BACnC;iCAAM,IAAI,qBAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,qBAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;gCACrE,cAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;6BACrC;iCAAM;gCACL,eAAe;gCACf,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;6BAC7C;yBACF;wBACD,MAAM;oBACR,KAAK,QAAQ;wBACX,eAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;wBAC/B,MAAM;oBACR;wBACE,iBAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;iBACpC;YAEH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AAhGD,8CAgGC","file":"AnnotationsHelper.js","sourcesContent":["import {assign, defaults, filter, get, isArray, isEmpty, isObjectLike, isUndefined, keys, merge} from 'lodash';\nimport {ClassRef} from './ClassRef';\nimport {MERGE_TYPE, METATYPE_ENTITY, METATYPE_PROPERTY, XS_ANNOTATION_OPTIONS_CACHE} from './Constants';\nimport {ClassUtils, MetadataStorage} from '@allgemein/base';\nimport {IPropertyExtentions} from '../api/IPropertyExtentions';\nimport {IClassRef} from '../api/IClassRef';\n\n\nexport class AnnotationsHelper {\n\n static forPropertyOn(object: Function, property: string, options: any, merge?: MERGE_TYPE) {\n const source = ClassUtils.getFunction(object);\n const classRefs: IClassRef[] = ClassRef.filter(c => c.getClass() === source);\n\n for (const ref of classRefs) {\n let prop = ref.getPropertyRef(property);\n if (prop) {\n const pOptions = prop.getOptions();\n defaults(pOptions, options);\n if (ref.hasEntityRef()) {\n const eOptions = ref.getEntityRef().getOptions();\n defaults(eOptions, options);\n }\n }\n }\n\n MetadataStorage.key(XS_ANNOTATION_OPTIONS_CACHE).push(<IPropertyExtentions>{\n type: METATYPE_PROPERTY,\n object: source,\n property: property,\n options: options,\n merge: merge ? merge : 'default'\n });\n }\n\n\n static forEntityOn(object: Function, options: any, merge?: MERGE_TYPE) {\n const source = ClassUtils.getFunction(object);\n const classRefs: IClassRef[] = ClassRef.filter(c => c.getClass() === source);\n\n for (const ref of classRefs) {\n if (ref) {\n let pOptions = ref.getOptions();\n defaults(pOptions, options);\n if (ref.hasEntityRef()) {\n const eOptions = ref.getEntityRef().getOptions();\n defaults(eOptions, options);\n }\n }\n }\n\n MetadataStorage.key(XS_ANNOTATION_OPTIONS_CACHE).push(<IPropertyExtentions>{\n type: METATYPE_ENTITY,\n object: source,\n options: options,\n merge: merge\n });\n }\n\n static merge(classRef: IClassRef, options: any, property: string = null) {\n if (!classRef) {\n return;\n }\n\n const object = classRef.getClass(true);\n const addOns: IPropertyExtentions[] = filter(MetadataStorage.key(XS_ANNOTATION_OPTIONS_CACHE), (x: IPropertyExtentions) =>\n property ?\n (classRef.isPlaceholder ? ClassUtils.getClassName(x.object) === classRef.name : x.object === object) &&\n x.property === property &&\n x.type == METATYPE_PROPERTY :\n (classRef.isPlaceholder ? ClassUtils.getClassName(x.object) === classRef.name : x.object === object) &&\n x.type == METATYPE_ENTITY\n );\n\n if (addOns) {\n addOns.forEach(addOn => {\n const mergeType: MERGE_TYPE = get(addOn, 'merge', 'default');\n switch (mergeType) {\n case 'merge':\n for (const k of keys(addOn.options)) {\n if (isUndefined(options[k]) || isEmpty(options[k])) {\n // create if not present\n options[k] = addOn.options[k];\n } else if (isArray(options[k])) {\n // add to array\n options[k].push(addOn.options[k]);\n } else if (isObjectLike(options[k]) && isObjectLike(addOn.options[k])) {\n merge(options[k], addOn.options[k]);\n } else {\n // create array\n options[k] = [options[k], addOn.options[k]];\n }\n }\n break;\n case 'assign':\n assign(options, addOn.options);\n break;\n default:\n defaults(options, addOn.options);\n }\n\n });\n }\n }\n}\n"],"sourceRoot":".."}
|