Skip to content

Commit

Permalink
fix: appropriately name helper func, update deps, license
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrazx committed Apr 2, 2021
1 parent 01a5062 commit 3a15786
Show file tree
Hide file tree
Showing 5 changed files with 1,707 additions and 1,255 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Jason Franz <jfrazx> staringblind at gmail.com
Copyright (c) 2021 Jason Franz <jfrazx> staringblind at gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
34 changes: 16 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@
"dependencies": {},
"devDependencies": {
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/jest": "^26.0.10",
"@types/mongoose": "^5.7.36",
"@typescript-eslint/parser": "^4.0.1",
"codecov": "^3.7.2",
"commitizen": "^4.2.1",
"@semantic-release/release-notes-generator": "^9.0.2",
"@types/jest": "^26.0.22",
"@types/mongoose": "^5.10.4",
"@typescript-eslint/parser": "^4.20.0",
"codecov": "^3.8.1",
"commitizen": "^4.2.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.7.0",
"husky": "^4.2.5",
"jest": "^26.4.2",
"mongodb-memory-server": "^6.6.6",
"mongoose": "^5.10.2",
"prettier": "^2.1.1",
"eslint": "^7.23.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"mongodb-memory-server": "^6.9.6",
"mongoose": "^5.12.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"semantic-release": "^17.1.1",
"semantic-release": "^17.4.2",
"travis-deploy-once": "^5.0.11",
"ts-jest": "^26.3.0",
"typescript": "^4.0.2"
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
},
"config": {
"commitizen": {
Expand All @@ -61,7 +61,5 @@
"type": "git",
"url": "https://github.com/jfrazx/mongoose-transient.git"
},
"peerDependencies": {
"mongoose": ">= 4.4.5"
}
"peerDependencies": {}
}
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ const setOptions = (path: string, trans: Transience): TransOpts => {
};

const determineLinkTo = (trans: Transience): string[] =>
isObject(trans) && trans.linkTo ? asArray(trans.linkTo) : [];
isTransientOptions(trans) && trans.linkTo ? asArray(trans.linkTo) : [];

const determineArgs = (trans: Transience): any[] =>
isObject(trans) && Array.isArray(trans.args) ? trans.args : [];
isTransientOptions(trans) && Array.isArray(trans.args) ? trans.args : [];

const determineGetter = (trans: Transience): TransientCaller =>
isObject(trans) && isFunction(trans.get) ? trans.get : defaultCaller;
isTransientOptions(trans) && isFunction(trans.get) ? trans.get : defaultCaller;

const determineSetter = (trans: Transience): TransientCaller =>
isFunction(trans)
? trans
: isObject(trans) && isFunction(trans.set)
: isTransientOptions(trans) && isFunction(trans.set)
? trans.set
: defaultCaller;

Expand All @@ -107,15 +107,15 @@ const defaultCaller: TransientCaller = (value: any) => value;
const determinePropertyName = (path: string, trans: Transience): string =>
isString(trans)
? trans
: isObject(trans) && isString(trans.as)
: isTransientOptions(trans) && isString(trans.as)
? trans.as
: `_${path}`;

const asArray = <T>(value: T | T[]): T[] => (Array.isArray(value) ? value : [value]);
const isFunction = (value: any): value is TransientCaller =>
typeof value === 'function';
const isString = (value: any): value is string => typeof value === 'string';
const isObject = (value: any): value is TransientOptions =>
const isTransientOptions = (value: any): value is TransientOptions =>
value && !Array.isArray(value) && typeof value === 'object';

export default transient;
12 changes: 7 additions & 5 deletions test/transient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { MongoMemoryReplSet } from 'mongodb-memory-server';
import * as mongoose from 'mongoose';
import transient from '../src';

const replSet = new MongoMemoryReplSet({
replSet: { storageEngine: 'wiredTiger' },
});

describe('Mongoose Transient', () => {
const replSet = new MongoMemoryReplSet({
replSet: { storageEngine: 'wiredTiger' },
});

beforeAll(async () => {
await replSet.waitUntilRunning();

const uri = await replSet.getUri();

await mongoose.connect(uri, {
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('Mongoose Transient', () => {
expect(user.another).toBeDefined();
});

it('should not have virtuals on pojo', () => {
it('should not have virtual properties on plain objects', () => {
const user = new User({
name: 'Bart',
password: 'eat!!!mysh0rts',
Expand Down Expand Up @@ -175,6 +176,7 @@ describe('Mongoose Transient', () => {

it('should not link to transient properties', () => {
mongoose.plugin(transient);

const schema = new mongoose.Schema({
testing: String,
moar: {
Expand Down
Loading

0 comments on commit 3a15786

Please sign in to comment.