-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak: Update the way changes and conditions are defined to allow arrays
- Loading branch information
1 parent
74f9477
commit 388f784
Showing
4 changed files
with
91 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
export { ObjectID, Binary } from "mongodb"; | ||
export { ObjectID, Binary } from "mongodb"; | ||
import { ObjectID } from "mongodb"; | ||
|
||
export type BSONType = | ||
undefined | ||
|null | ||
|number | ||
|string|symbol | ||
|BSONObject | ||
|BSONArray | ||
|ObjectID | ||
|boolean | ||
|Date | ||
|RegExp; | ||
|
||
export interface BSONObject { | ||
[property: string]: BSONType; | ||
} | ||
|
||
export interface BSONArray { | ||
[property: number]: BSONType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
import {ObjectID} from "mongodb"; | ||
|
||
export type UnderlyingBSONType = null | ||
|number | ||
|string|symbol | ||
|{[property: string]: UnderlyingBSONType;} | ||
//|UnderlyingBSONType[] | ||
|ObjectID | ||
|boolean | ||
|Date | ||
|RegExp; | ||
import {BSONType, BSONArray, ObjectID} from "./BSON"; | ||
|
||
export interface Conditions { | ||
[property: string]: { | ||
$eq?: UnderlyingBSONType; | ||
$ne?: UnderlyingBSONType; | ||
$in?: UnderlyingBSONType[]; | ||
$nin?: UnderlyingBSONType[]; | ||
$eq?: BSONType; | ||
$ne?: BSONType; | ||
$in?: BSONArray; | ||
$nin?: BSONArray; | ||
$elemMatch?: Conditions; | ||
$gt?: UnderlyingBSONType; | ||
$gte?: UnderlyingBSONType; | ||
$lt?: UnderlyingBSONType; | ||
$lte?: UnderlyingBSONType; | ||
}|UnderlyingBSONType; | ||
$gt?: BSONType; | ||
$gte?: BSONType; | ||
$lt?: BSONType; | ||
$lte?: BSONType; | ||
}|BSONType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as Iridium from "../iridium"; | ||
import * as chai from "chai"; | ||
|
||
interface Document { | ||
_id?: string; | ||
path: { | ||
type: "LineString"; | ||
coordinates: number[][]; | ||
}; | ||
} | ||
|
||
@Iridium.Collection("test") | ||
class Instance extends Iridium.Instance<Document, Instance> { | ||
@Iridium.ObjectID | ||
_id: string; | ||
|
||
@Iridium.Property({ | ||
type: /^LineString$/, | ||
coordinates: [[Number, 2, 2]] | ||
}) | ||
path: { | ||
type: "LineString"; | ||
coordinates: number[][]; | ||
}; | ||
} | ||
|
||
class Core extends Iridium.Core { | ||
Model = new Iridium.Model<Document, Instance>(this, Instance); | ||
} | ||
|
||
describe("Changes", () => { | ||
let core = new Core("mongodb://localhost/iridium_test"); | ||
|
||
describe("should allow you to specify valid operations", () => { | ||
it("should allow you to use the $push operator", () => { | ||
return core.Model.update({}, { | ||
$push: { | ||
"path.coordinates": { | ||
$each: [[1, 2]], | ||
$position: 1, | ||
$sort: { a: 1 } | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |