summaryrefslogtreecommitdiff
path: root/src/misc/cafy-id.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/cafy-id.ts')
-rw-r--r--src/misc/cafy-id.ts29
1 files changed, 2 insertions, 27 deletions
diff --git a/src/misc/cafy-id.ts b/src/misc/cafy-id.ts
index bc8fe4ea2b..39886611e1 100644
--- a/src/misc/cafy-id.ts
+++ b/src/misc/cafy-id.ts
@@ -1,38 +1,13 @@
-import * as mongo from 'mongodb';
import { Context } from 'cafy';
-import isObjectId from './is-objectid';
-export const isAnId = (x: any) => mongo.ObjectID.isValid(x);
-export const isNotAnId = (x: any) => !isAnId(x);
-export const transform = (x: string | mongo.ObjectID): mongo.ObjectID => {
- if (x === undefined) return undefined;
- if (x === null) return null;
-
- if (isAnId(x) && !isObjectId(x)) {
- return new mongo.ObjectID(x);
- } else {
- return x as mongo.ObjectID;
- }
-};
-export const transformMany = (xs: (string | mongo.ObjectID)[]): mongo.ObjectID[] => {
- if (xs == null) return null;
-
- return xs.map(x => transform(x));
-};
-
-export type ObjectId = mongo.ObjectID;
-
-/**
- * ID
- */
-export default class ID<Maybe = string> extends Context<string | Maybe> {
+export class ID<Maybe = string> extends Context<string | (Maybe extends {} ? string : Maybe)> {
public readonly name = 'ID';
constructor(optional = false, nullable = false) {
super(optional, nullable);
this.push((v: any) => {
- if (!isObjectId(v) && isNotAnId(v)) {
+ if (typeof v !== 'string') {
return new Error('must-be-an-id');
}
return true;