Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

type-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-mongodb - npm Package Compare versions

Comparing version 1.0.0-beta.14 to 1.0.0-beta.15

1

lib/decorators/index.d.ts

@@ -17,3 +17,2 @@ import 'reflect-metadata';

create?: boolean;
createJSValue?: (v: any) => any;
}

@@ -20,0 +19,0 @@ export declare function Field(options?: FieldOptions): PropertyDecorator;

6

lib/decorators/index.js

@@ -37,3 +37,7 @@ "use strict";

function addFieldDefinition(target, field, options, embedded) {
const def = Object.assign(Object.assign({}, options), { DocumentClass: target.constructor, propertyName: field, fieldName: options.name || field, isId: options.isId === true, isEmbedded: typeof embedded !== 'undefined', embedded, type: reflection_1.fieldToType(target, field, options.type), shouldCreateJSValue: typeof options.create === 'boolean' ? options.create : false });
const def = Object.assign(Object.assign(Object.assign(Object.assign({}, options), { DocumentClass: target.constructor, propertyName: field, fieldName: options.name || field, isId: options.isId === true, isEmbedded: typeof embedded !== 'undefined', embedded }), reflection_1.fieldToType(target, field, options.type)), { shouldCreateJSValue: typeof options.create === 'boolean' ? options.create : false });
if (def.type && def.typeIsArray && def.shouldCreateJSValue) {
console.log(def.type, def.typeIsArray, def.shouldCreateJSValue, options.create);
errors_1.InternalError.throw(`Option "create" is not supported for array types for property "${def.propertyName}" in "${def.DocumentClass.name}"`);
}
if (definitionStorage_1.definitionStorage.fields.has(def.DocumentClass)) {

@@ -40,0 +44,0 @@ definitionStorage_1.definitionStorage.fields.get(def.DocumentClass).set(field, def);

@@ -18,2 +18,3 @@ import { DocumentClass, Newable } from '../typings';

type: Type;
typeIsArray: boolean;
propertyName: string;

@@ -20,0 +21,0 @@ fieldName: string;

@@ -21,2 +21,3 @@ import { Newable } from '../typings';

readonly type: Type;
readonly typeIsArray: boolean;
readonly shouldCreateJSValue: boolean;

@@ -23,0 +24,0 @@ constructor(opts: FieldMetadataOpts);

@@ -18,2 +18,3 @@ "use strict";

this.type = opts.type;
this.typeIsArray = opts.typeIsArray;
this.shouldCreateJSValue = opts.shouldCreateJSValue;

@@ -20,0 +21,0 @@ if (this.type && !(this.type instanceof types_1.Type)) {

@@ -123,3 +123,5 @@ "use strict";

if (typeof ${variable} === 'undefined') {
const ${createJsVar} = ${typeVar}.createJSValue();
${fieldMetadata.typeIsArray
? `const ${createJsVar} = [${typeVar}.createJSValue()];`
: `const ${createJsVar} = ${typeVar}.createJSValue();`}

@@ -135,3 +137,7 @@ if (typeof ${createJsVar} !== 'undefined') {

if (typeof source["${accessor}"] !== 'undefined') {
target["${setter}"] = ${typeVar}.${convertFn}(source["${accessor}"]);
if (Array.isArray(source["${accessor}"])) {
target["${setter}"] = source["${accessor}"].map(v => ${typeVar}.${convertFn}(v));
} else {
target["${setter}"] = ${typeVar}.${convertFn}(source["${accessor}"]);
}
}

@@ -138,0 +144,0 @@ `;

@@ -44,4 +44,4 @@ import { Newable } from '../typings';

*/
static getType<M, D>(Ctor: Newable<Type<M, D>>): Type<M, D>;
static getType<M, D>(type: Newable<Type<M, D>> | Type<M, D>): Type<M, D>;
}
//# sourceMappingURL=Type.d.ts.map

@@ -67,6 +67,9 @@ "use strict";

*/
static getType(Ctor) {
const key = Ctor.name;
static getType(type) {
if (type instanceof Type) {
return type;
}
const key = type.name;
if (!Type.types.has(key)) {
Type.types.set(key, new Ctor());
Type.types.set(key, new type());
}

@@ -73,0 +76,0 @@ return Type.types.get(key);

import 'reflect-metadata';
import { Newable } from '../typings';
import { Type } from '../types';
export declare function fieldToType(target: Object, name: string, type?: Type | Newable<Type>): Type | undefined;
import { FieldDefinition } from 'src/metadata';
export declare function fieldToType(target: Object, name: string, type?: Type | Newable<Type>): Pick<FieldDefinition, 'type' | 'typeIsArray'>;
//# sourceMappingURL=reflection.d.ts.map

@@ -7,12 +7,21 @@ "use strict";

function fieldToType(target, name, type) {
const designType = Reflect.getMetadata('design:type', target, name);
if (typeof type !== 'undefined') {
return type instanceof types_1.Type ? type : types_1.Type.getType(type);
return {
type: type instanceof types_1.Type ? type : types_1.Type.getType(type),
typeIsArray: designType === Array
};
}
const designType = Reflect.getMetadata('design:type', target, name);
if (typeof (designType === null || designType === void 0 ? void 0 : designType.name) !== 'string') {
return;
return {
type: undefined,
typeIsArray: false
};
}
switch (designType.name.toLowerCase()) {
case 'objectid':
return types_1.Type.getType(types_1.ObjectIdType);
return {
type: types_1.Type.getType(types_1.ObjectIdType),
typeIsArray: false
};
}

@@ -19,0 +28,0 @@ }

{
"name": "type-mongodb",
"version": "1.0.0-beta.14",
"version": "1.0.0-beta.15",
"description": "A simple decorator based MongoDB ODM.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/j/type-mongodb",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc