New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@girin/typemongo

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@girin/typemongo - npm Package Compare versions

Comparing version 0.5.0-alpha.7 to 0.5.1-alpha.0

24

lib/models/decorators.d.ts
import { ModelClass } from './Model';
import { EmbedClass } from './Embed';
import { MaybeThunk } from '../utils';
export declare function field(alias?: string): (prototype: any, propertyKey: string) => void;

@@ -9,11 +10,24 @@ /**

*/
export declare function hasOne(modelClass: ModelClass<any>, alias?: string): (prototype: any, propertyKey: string) => void;
export declare function hasOneField(modelClass: MaybeThunk<ModelClass<any>>, alias?: string): (prototype: any, propertyKey: string) => void;
/**
* field containing list of other model's _ids
* field containing a list of other model's _ids
* @param modelClass
* @param alias
*/
export declare function hasMany(modelClass: ModelClass<any>, alias?: string): (prototype: any, propertyKey: string) => void;
export declare function embedOne(embedClass: EmbedClass<any>, alias?: string): (prototype: any, propertyKey: string) => void;
export declare function embedMany(embedClass: EmbedClass<any>, alias?: string): (prototype: any, propertyKey: string) => void;
export declare function hasManyField(modelClass: MaybeThunk<ModelClass<any>>, alias?: string): (prototype: any, propertyKey: string) => void;
/**
* field containing other model's $source
* @param embedClassOrThunk
* @param alias
*/
export declare function embedOneField(embedClassOrThunk: MaybeThunk<EmbedClass<any>>, alias?: string): (prototype: any, propertyKey: string) => void;
/**
* field containing a list of other model's $source
* @param embedClassOrThunk
* @param alias
*/
export declare function embedManyField(embedClassOrThunk: MaybeThunk<EmbedClass<any>>, alias?: string): (prototype: any, propertyKey: string) => void;
export declare class TypeMongoPropertyDecoratorError extends Error {
constructor(prototype: Object, propertyKey: string, message?: string);
}
//# sourceMappingURL=decorators.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const association_1 = require("./association");
const utils_1 = require("../utils");
function field(alias) {

@@ -20,7 +21,10 @@ return function (prototype, propertyKey) {

*/
function hasOne(modelClass, alias) {
function hasOneField(modelClass, alias) {
return function (prototype, propertyKey) {
if (modelClass === undefined) {
throw new TypeMongoPropertyDecoratorError(prototype, propertyKey, `The first argument given to @${hasOneField.name} decorator should be a class but undefined.`);
}
const fieldName = alias || propertyKey;
const get = function () {
return new association_1.HasOne(modelClass, this, fieldName);
return new association_1.HasOne(utils_1.resolveMaybeThunk(modelClass), this, fieldName);
};

@@ -30,13 +34,16 @@ Object.defineProperty(prototype, propertyKey, { get });

}
exports.hasOne = hasOne;
exports.hasOneField = hasOneField;
/**
* field containing list of other model's _ids
* field containing a list of other model's _ids
* @param modelClass
* @param alias
*/
function hasMany(modelClass, alias) {
function hasManyField(modelClass, alias) {
return function (prototype, propertyKey) {
if (modelClass === undefined) {
throw new TypeMongoPropertyDecoratorError(prototype, propertyKey, `The first argument given to @${hasManyField.name} decorator should not be undefined.`);
}
const fieldName = alias || propertyKey;
const get = function () {
return new association_1.HasMany(modelClass, this, fieldName);
return new association_1.HasMany(utils_1.resolveMaybeThunk(modelClass), this, fieldName);
};

@@ -46,7 +53,16 @@ Object.defineProperty(prototype, propertyKey, { get });

}
exports.hasMany = hasMany;
function embedOne(embedClass, alias) {
exports.hasManyField = hasManyField;
/**
* field containing other model's $source
* @param embedClassOrThunk
* @param alias
*/
function embedOneField(embedClassOrThunk, alias) {
return function (prototype, propertyKey) {
if (embedClassOrThunk === undefined) {
throw new TypeMongoPropertyDecoratorError(prototype, propertyKey, `The first argument given to @${embedOneField.name} decorator should not be undefined.`);
}
const fieldName = alias || propertyKey;
const get = function () {
const embedClass = utils_1.resolveMaybeThunk(embedClassOrThunk);
return this.$source[fieldName] && new embedClass(this.$source[fieldName]);

@@ -60,7 +76,16 @@ };

}
exports.embedOne = embedOne;
function embedMany(embedClass, alias) {
exports.embedOneField = embedOneField;
/**
* field containing a list of other model's $source
* @param embedClassOrThunk
* @param alias
*/
function embedManyField(embedClassOrThunk, alias) {
return function (prototype, propertyKey) {
if (embedClassOrThunk === undefined) {
throw new TypeMongoPropertyDecoratorError(prototype, propertyKey, `The first argument given to @${embedManyField.name} decorator should not be undefined.`);
}
const fieldName = alias || propertyKey;
const get = function () {
const embedClass = utils_1.resolveMaybeThunk(embedClassOrThunk);
return this.$source[fieldName] && this.$source[fieldName].map((value) => new embedClass(value));

@@ -74,3 +99,11 @@ };

}
exports.embedMany = embedMany;
exports.embedManyField = embedManyField;
class TypeMongoPropertyDecoratorError extends Error {
constructor(prototype, propertyKey, message) {
const fullMessage = `TypeMongoPropertyDecoratorError: ${prototype.constructor.toString()}.prototype.${propertyKey}`;
+(message ? ': ' + message : '');
super(fullMessage);
}
}
exports.TypeMongoPropertyDecoratorError = TypeMongoPropertyDecoratorError;
//# sourceMappingURL=decorators.js.map

@@ -5,2 +5,3 @@ export * from './Model';

export * from './Embed';
export * from './association';
//# sourceMappingURL=index.d.ts.map

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

__export(require("./Embed"));
__export(require("./association"));
//# sourceMappingURL=index.js.map

@@ -12,2 +12,4 @@ export declare class CompositeKeySorter<T> {

}
export declare function resolveMaybeThunk<T>(maybeThunk: MaybeThunk<T>): T;
export declare type MaybeThunk<T> = T | (() => T);
//# sourceMappingURL=utils.d.ts.map

@@ -38,2 +38,10 @@ "use strict";

exports.CompositeKeySorter = CompositeKeySorter;
function resolveMaybeThunk(maybeThunk) {
// Arrow functions have no prototype
if (maybeThunk instanceof Function && maybeThunk.prototype === undefined) {
return maybeThunk();
}
return maybeThunk;
}
exports.resolveMaybeThunk = resolveMaybeThunk;
//# sourceMappingURL=utils.js.map
{
"name": "@girin/typemongo",
"version": "0.5.0-alpha.7",
"version": "0.5.1-alpha.0",
"description": "Lightweight MongoDB ODM optimized for GraphQL",

@@ -28,3 +28,3 @@ "main": "./lib/index.js",

"dependencies": {
"@girin/connection": "^0.5.0-alpha.7",
"@girin/connection": "^0.5.1-alpha.0",
"dataloader": "^1.4.0"

@@ -35,3 +35,3 @@ },

},
"gitHead": "370b5aa68131e09f7e05bb3886cb167d00595278",
"gitHead": "08ac7fa9d42f17329e3e197e69540b1e26c32490",
"files": [

@@ -38,0 +38,0 @@ "lib",

import { Model, ModelClass } from './Model';
import { HasOne, HasMany } from './association';
import { Embed, EmbedClass } from './Embed';
import { MaybeThunk, resolveMaybeThunk } from '../utils';

@@ -22,7 +23,15 @@

*/
export function hasOne(modelClass: ModelClass<any>, alias?: string) {
export function hasOneField(modelClass: MaybeThunk<ModelClass<any>>, alias?: string) {
return function(prototype: any, propertyKey: string) {
if (modelClass === undefined) {
throw new TypeMongoPropertyDecoratorError(
prototype,
propertyKey,
`The first argument given to @${hasOneField.name} decorator should be a class but undefined.`
);
}
const fieldName = alias || propertyKey;
const get = function(this: Model) {
return new HasOne(modelClass, this, fieldName);
return new HasOne(resolveMaybeThunk(modelClass), this, fieldName);
};

@@ -34,11 +43,19 @@ Object.defineProperty(prototype, propertyKey, { get });

/**
* field containing list of other model's _ids
* field containing a list of other model's _ids
* @param modelClass
* @param alias
*/
export function hasMany(modelClass: ModelClass<any>, alias?: string) {
export function hasManyField(modelClass: MaybeThunk<ModelClass<any>>, alias?: string) {
return function(prototype: any, propertyKey: string) {
if (modelClass === undefined) {
throw new TypeMongoPropertyDecoratorError(
prototype,
propertyKey,
`The first argument given to @${hasManyField.name} decorator should not be undefined.`
);
}
const fieldName = alias || propertyKey;
const get = function(this: Model) {
return new HasMany(modelClass, this, fieldName);
return new HasMany(resolveMaybeThunk(modelClass), this, fieldName);
};

@@ -49,7 +66,21 @@ Object.defineProperty(prototype, propertyKey, { get });

/**
* field containing other model's $source
* @param embedClassOrThunk
* @param alias
*/
export function embedOneField(embedClassOrThunk: MaybeThunk<EmbedClass<any>>, alias?: string) {
return function(prototype: any, propertyKey: string) {
export function embedOne(embedClass: EmbedClass<any>, alias?: string) {
return function(prototype: any, propertyKey: string) {
if (embedClassOrThunk === undefined) {
throw new TypeMongoPropertyDecoratorError(
prototype,
propertyKey,
`The first argument given to @${embedOneField.name} decorator should not be undefined.`
);
}
const fieldName = alias || propertyKey;
const get = function(this: Model) {
const embedClass = resolveMaybeThunk(embedClassOrThunk);
return this.$source[fieldName] && new embedClass(this.$source[fieldName]);

@@ -64,6 +95,21 @@ };

export function embedMany(embedClass: EmbedClass<any>, alias?: string) {
/**
* field containing a list of other model's $source
* @param embedClassOrThunk
* @param alias
*/
export function embedManyField(embedClassOrThunk: MaybeThunk<EmbedClass<any>>, alias?: string) {
return function(prototype: any, propertyKey: string) {
if (embedClassOrThunk === undefined) {
throw new TypeMongoPropertyDecoratorError(
prototype,
propertyKey,
`The first argument given to @${embedManyField.name} decorator should not be undefined.`
);
}
const fieldName = alias || propertyKey;
const get = function(this: Model) {
const embedClass = resolveMaybeThunk(embedClassOrThunk);
return this.$source[fieldName] && this.$source[fieldName].map((value: any) => new embedClass(value));

@@ -77,1 +123,10 @@ };

}
export class TypeMongoPropertyDecoratorError extends Error {
constructor(prototype: Object, propertyKey: string, message?: string) {
const fullMessage = `TypeMongoPropertyDecoratorError: ${prototype.constructor.toString()}.prototype.${propertyKey}`;
+ (message ? ': ' + message : '');
super(fullMessage);
}
}

@@ -5,1 +5,2 @@ export * from './Model';

export * from './Embed';
export * from './association';

@@ -34,1 +34,11 @@ export class CompositeKeySorter<T> {

}
export function resolveMaybeThunk<T>(maybeThunk: MaybeThunk<T>): T {
// Arrow functions have no prototype
if (maybeThunk instanceof Function && maybeThunk.prototype === undefined) {
return maybeThunk() as T;
}
return maybeThunk as unknown as T;
}
export type MaybeThunk<T> = T | (() => T);

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