mongo-typed 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/array.d.ts +2 -0
- package/dist/array.js +1 -0
- package/dist/bson-types.d.ts +57 -0
- package/dist/bson-types.js +23 -0
- package/dist/dot-notation.d.ts +12 -0
- package/dist/dot-notation.js +2 -0
- package/dist/dot-notation.spec.d.ts +1 -0
- package/dist/dot-notation.spec.js +48 -0
- package/dist/expr.d.ts +334 -0
- package/dist/expr.js +1 -0
- package/dist/expr.spec.d.ts +1 -0
- package/dist/expr.spec.js +1 -0
- package/dist/filter.d.ts +72 -0
- package/dist/filter.js +2 -0
- package/dist/filter.spec.d.ts +1 -0
- package/dist/filter.spec.js +192 -0
- package/dist/geo-json.d.ts +25 -0
- package/dist/geo-json.js +1 -0
- package/dist/identifiable.d.ts +4 -0
- package/dist/identifiable.js +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/json-schema/index.d.ts +2 -0
- package/dist/json-schema/index.js +2 -0
- package/dist/json-schema/keywords.d.ts +5 -0
- package/dist/json-schema/keywords.js +1 -0
- package/dist/json-schema/schema.d.ts +440 -0
- package/dist/json-schema/schema.js +36 -0
- package/dist/json-schema/types.d.ts +18 -0
- package/dist/json-schema/types.js +8 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +1 -0
- package/dist/update.d.ts +63 -0
- package/dist/update.js +1 -0
- package/dist/update.spec.d.ts +1 -0
- package/dist/update.spec.js +22 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SecureDataSystems
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# mongo-typed
|
|
2
|
+
|
|
3
|
+
TypeScript utility types for building strongly-typed MongoDB filters, and updates — without adding dependencies.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`mongo-typed` provides type-safe MongoDB-style query and update utilities in TypeScript. It is designed to assist with building fully-typed data repository layers or services that interact with MongoDB-like syntax, without relying on external libraries or runtime packages.
|
|
8
|
+
|
|
9
|
+
Whether you're working with an actual MongoDB database or implementing similar patterns in your application logic, `mongo-typed` gives you strong typing for common Mongo operations like filters, and updates.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🧠 Fully typed **filter** support (including `$and`, `$or`, `$in`, `$elemMatch`, etc.)
|
|
14
|
+
- ✍️ Strongly typed **update** operations (e.g., `$set`, `$inc`, `$unset`, etc.)
|
|
15
|
+
- 💡 No dependencies — pure TypeScript
|
|
16
|
+
- 🔐 Helps catch invalid Mongo-like queries at compile time
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add mongo-typed
|
|
22
|
+
# or
|
|
23
|
+
npm install mongo-typed
|
|
24
|
+
# or
|
|
25
|
+
yarn add mongo-typed
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Basic Filter Type
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Filter } from 'mongo-typed';
|
|
34
|
+
|
|
35
|
+
type User = {
|
|
36
|
+
_id: string;
|
|
37
|
+
email: string;
|
|
38
|
+
age: number;
|
|
39
|
+
roles: string[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const query: Filter<User> = {
|
|
43
|
+
age: { $gte: 18 },
|
|
44
|
+
roles: { $in: ['admin', 'user'] },
|
|
45
|
+
$or: [
|
|
46
|
+
{ email: /@example\.com$/ },
|
|
47
|
+
{ email: { $exists: false } }
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Basic Update Type
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Update } from 'mongo-typed';
|
|
56
|
+
|
|
57
|
+
const update: Update<User> = {
|
|
58
|
+
$set: {
|
|
59
|
+
email: 'new@email.com'
|
|
60
|
+
},
|
|
61
|
+
$inc: {
|
|
62
|
+
age: 1
|
|
63
|
+
},
|
|
64
|
+
$unset: {
|
|
65
|
+
roles: true
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Aggregation Types (Coming Soon)
|
|
71
|
+
|
|
72
|
+
Aggregation support is in active development and aims to type:
|
|
73
|
+
- `$match`
|
|
74
|
+
- `$group`
|
|
75
|
+
- `$project`
|
|
76
|
+
- `$sort`, `$limit`, `$lookup`, and more
|
|
77
|
+
|
|
78
|
+
## Why Use `mongo-typed`?
|
|
79
|
+
|
|
80
|
+
TypeScript developers working with MongoDB often find themselves wishing for deeper type safety on filters and updates — especially in larger projects or those with repository abstraction layers.
|
|
81
|
+
|
|
82
|
+
`mongo-typed` solves this by bringing compile-time validation of Mongo-style operations, helping prevent costly runtime errors due to typos or invalid operations.
|
|
83
|
+
|
|
84
|
+
## Status
|
|
85
|
+
|
|
86
|
+
- ✅ Filter types – stable
|
|
87
|
+
- ✅ Update types – in progress
|
|
88
|
+
- 🧪 Aggregation types – coming soon
|
|
89
|
+
- 🔄 Actively maintained
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
|
|
93
|
+
Contributions and suggestions are welcome! Please open issues or PRs to help improve support for advanced MongoDB operators or aggregations.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
package/dist/array.d.ts
ADDED
package/dist/array.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EnhancedOmit } from './types.js';
|
|
2
|
+
export declare const BsonType: {
|
|
3
|
+
readonly array: "array";
|
|
4
|
+
readonly binData: "binData";
|
|
5
|
+
readonly bool: "bool";
|
|
6
|
+
readonly date: "date";
|
|
7
|
+
readonly dbPointer: "dbPointer";
|
|
8
|
+
readonly decimal: "decimal";
|
|
9
|
+
readonly double: "double";
|
|
10
|
+
readonly int: "int";
|
|
11
|
+
readonly javascript: "javascript";
|
|
12
|
+
readonly javascriptWithScope: "javascriptWithScope";
|
|
13
|
+
readonly long: "long";
|
|
14
|
+
readonly maxKey: "maxKey";
|
|
15
|
+
readonly minKey: "minKey";
|
|
16
|
+
readonly null: "null";
|
|
17
|
+
readonly object: "object";
|
|
18
|
+
readonly objectId: "objectId";
|
|
19
|
+
readonly regex: "regex";
|
|
20
|
+
readonly string: "string";
|
|
21
|
+
readonly symbol: "symbol";
|
|
22
|
+
readonly timestamp: "timestamp";
|
|
23
|
+
readonly undefined: "undefined";
|
|
24
|
+
};
|
|
25
|
+
export declare const BsonTypeNumeric: Readonly<{
|
|
26
|
+
readonly array: 4;
|
|
27
|
+
readonly binData: 5;
|
|
28
|
+
readonly bool: 8;
|
|
29
|
+
readonly date: 9;
|
|
30
|
+
readonly dbPointer: 12;
|
|
31
|
+
readonly decimal: 19;
|
|
32
|
+
readonly double: 1;
|
|
33
|
+
readonly int: 16;
|
|
34
|
+
readonly javascript: 13;
|
|
35
|
+
readonly javascriptWithScope: 15;
|
|
36
|
+
readonly long: 18;
|
|
37
|
+
readonly maxKey: 127;
|
|
38
|
+
readonly minKey: -1;
|
|
39
|
+
readonly null: 10;
|
|
40
|
+
readonly object: 3;
|
|
41
|
+
readonly objectId: 7;
|
|
42
|
+
readonly regex: 11;
|
|
43
|
+
readonly string: 2;
|
|
44
|
+
readonly symbol: 14;
|
|
45
|
+
readonly timestamp: 17;
|
|
46
|
+
readonly undefined: 6;
|
|
47
|
+
}>;
|
|
48
|
+
export declare type BsonType = typeof BsonType[keyof typeof BsonType];
|
|
49
|
+
export declare type BsonTypeNumeric = (typeof BsonTypeNumeric)[keyof typeof BsonTypeNumeric];
|
|
50
|
+
export declare type IntegerType = bigint | number;
|
|
51
|
+
export declare type NumericType = IntegerType;
|
|
52
|
+
export declare type RegExpOrString<T> = T extends string ? RegExp | T : T;
|
|
53
|
+
/** Add an _id field to an object shaped type */
|
|
54
|
+
export declare type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
|
|
55
|
+
_id: string;
|
|
56
|
+
};
|
|
57
|
+
export type NumericBsonType = 1 | 16 | 18 | 19 | 'decimal' | 'double' | 'int' | 'long';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const BsonType = {
|
|
2
|
+
array: 'array',
|
|
3
|
+
binData: 'binData',
|
|
4
|
+
bool: 'bool',
|
|
5
|
+
date: 'date',
|
|
6
|
+
dbPointer: 'dbPointer',
|
|
7
|
+
decimal: 'decimal',
|
|
8
|
+
double: 'double',
|
|
9
|
+
int: 'int',
|
|
10
|
+
javascript: 'javascript',
|
|
11
|
+
javascriptWithScope: 'javascriptWithScope',
|
|
12
|
+
long: 'long',
|
|
13
|
+
maxKey: 'maxKey',
|
|
14
|
+
minKey: 'minKey',
|
|
15
|
+
null: 'null',
|
|
16
|
+
object: 'object',
|
|
17
|
+
objectId: 'objectId',
|
|
18
|
+
regex: 'regex',
|
|
19
|
+
string: 'string',
|
|
20
|
+
symbol: 'symbol',
|
|
21
|
+
timestamp: 'timestamp',
|
|
22
|
+
undefined: 'undefined'
|
|
23
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Dot notation that includes numeric array indices and properly maps for use in object keys */
|
|
2
|
+
import { And, NonNullableField } from './types.js';
|
|
3
|
+
export type DotNotation<T extends object, TAllowPlaceholder extends boolean = false, TPrefix extends string = '', TDepth extends number[] = []> = TDepth['length'] extends 9 ? never : T extends readonly (infer U)[] ? (`${TPrefix}${number}` | DotNotation<NonNullableField<U> extends object ? NonNullableField<U> : never, TAllowPlaceholder, `${TPrefix}${number}.`, [...TDepth, 1]> | DotNotation<NonNullableField<U> extends object ? NonNullableField<U> : never, TAllowPlaceholder, `${TPrefix}`, [...TDepth, 1]> | (TAllowPlaceholder extends true ? (`${TPrefix}$[${string}]` | `${TPrefix}$` | DotNotation<NonNullableField<U> extends object ? NonNullableField<U> : never, TAllowPlaceholder, `${TPrefix}$.`, [...TDepth, 1]> | DotNotation<NonNullableField<U> extends object ? NonNullableField<U> : never, TAllowPlaceholder, `${TPrefix}$[${string}].`, [...TDepth, 1]> | DotNotation<NonNullableField<U> extends object ? NonNullableField<U> : never, TAllowPlaceholder, `${TPrefix}$[].`, [...TDepth, 1]>) : never)) : {
|
|
4
|
+
[K in keyof T & string]: T[K] extends (...args: any[]) => any ? never : (`${TPrefix}${K}` | DotNotation<NonNullableField<T[K]> extends object ? NonNullableField<T[K]> : never, TAllowPlaceholder, `${TPrefix}${K}.`, [...TDepth, 1]>);
|
|
5
|
+
}[keyof T & string];
|
|
6
|
+
/** Resolves a dot-notated path to the corresponding type, including array indexing */
|
|
7
|
+
export type DotPathValue<T, TPath extends string, TAllowPlaceholder extends boolean = false, TCheckInArray extends boolean = false, TIsInArray extends boolean = false, TDepth extends number[] = []> = TDepth['length'] extends 9 ? never : TPath extends `${infer Key}.${infer Rest}` ? T extends readonly (infer U)[] ? Key extends `${number}` ? DotPathValue<U, Rest, TAllowPlaceholder, TCheckInArray, TIsInArray, [...TDepth, 1]> : TAllowPlaceholder extends true ? Key extends `$[${string}]` | `$[]` | `$` ? DotPathValue<U, Rest, TAllowPlaceholder, TCheckInArray, true, [...TDepth, 1]> : never : never : Key extends keyof T ? DotPathValue<NonNullable<T[Key]>, Rest, TAllowPlaceholder, TCheckInArray, TIsInArray, [...TDepth, 1]> : never : T extends readonly (infer U)[] ? TPath extends `${number}` ? And<TIsInArray, TCheckInArray, U[], U> : TAllowPlaceholder extends true ? TPath extends `$[${string}]` | `$[]` | `$` ? TCheckInArray extends true ? U[] : U : TPath extends keyof U ? TCheckInArray extends true ? U[TPath][] : U[TPath] : never : TPath extends keyof U ? TCheckInArray extends true ? U[TPath][] : U[TPath] : never : TPath extends keyof T ? And<TIsInArray, TCheckInArray, T[TPath][], T[TPath]> : never;
|
|
8
|
+
export type OnlyFieldsOfTypeDotNotation<T extends object, TFieldType, TAllowPlaceholder extends boolean = false, TCheckInArray extends boolean = false, TAssignableType = never> = {
|
|
9
|
+
[P in DotNotation<T, TAllowPlaceholder> as NonNullableField<DotPathValue<T, P, TAllowPlaceholder, TCheckInArray>> extends TFieldType ? P : never]?: [
|
|
10
|
+
TAssignableType
|
|
11
|
+
] extends [never] ? DotPathValue<T, P, TAllowPlaceholder, TCheckInArray> : TAssignableType;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
describe('DotNotation', () => {
|
|
4
|
+
it('should include top-level keys', () => {
|
|
5
|
+
});
|
|
6
|
+
it('should include nested keys', () => {
|
|
7
|
+
});
|
|
8
|
+
it('should include array index paths', () => {
|
|
9
|
+
});
|
|
10
|
+
it('should include deep dot notation with mixed levels', () => {
|
|
11
|
+
});
|
|
12
|
+
it('should support placeholder paths if enabled', () => {
|
|
13
|
+
});
|
|
14
|
+
it('should stop recursion at max depth', () => {
|
|
15
|
+
});
|
|
16
|
+
it('should treat dates as simple types', () => {
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe('DotPathValue', () => {
|
|
20
|
+
it('should resolve top-level fields', () => {
|
|
21
|
+
});
|
|
22
|
+
it('should resolve nested fields', () => {
|
|
23
|
+
});
|
|
24
|
+
it('should resolve array index values', () => {
|
|
25
|
+
});
|
|
26
|
+
it('should resolve placeholder array paths (TCheckInArray = true)', () => {
|
|
27
|
+
});
|
|
28
|
+
it('should resolve placeholder array paths (TCheckInArray = false)', () => {
|
|
29
|
+
});
|
|
30
|
+
it('should resolve deeply nested placeholders (TCheckInArray = true)', () => {
|
|
31
|
+
});
|
|
32
|
+
it('should resolve deeply nested placeholders (TCheckInArray = false)', () => {
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('OnlyFieldsOfTypeDotNotation', () => {
|
|
36
|
+
it('should include only number fields', () => {
|
|
37
|
+
});
|
|
38
|
+
it('should include only string fields', () => {
|
|
39
|
+
});
|
|
40
|
+
it('should include only boolean fields', () => {
|
|
41
|
+
});
|
|
42
|
+
it('should include only Date fields', () => {
|
|
43
|
+
});
|
|
44
|
+
it('should allow custom assignable type', () => {
|
|
45
|
+
});
|
|
46
|
+
it('should support placeholder dot notation when enabled', () => {
|
|
47
|
+
});
|
|
48
|
+
});
|
package/dist/expr.d.ts
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { NumericBsonType } from './bson-types.js';
|
|
2
|
+
import { DotNotation } from './dot-notation.js';
|
|
3
|
+
export type ArrayExpr<TInput extends object> = Array<unknown> | FieldRef<TInput> | {
|
|
4
|
+
$concatArrays: ArrayExpr<TInput>[];
|
|
5
|
+
} | {
|
|
6
|
+
$filter: {
|
|
7
|
+
as?: string;
|
|
8
|
+
cond: BooleanExpr<TInput>;
|
|
9
|
+
input: ArrayExpr<TInput>;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
$literal: Array<unknown>;
|
|
13
|
+
} | {
|
|
14
|
+
$map: {
|
|
15
|
+
as?: string;
|
|
16
|
+
in: Expr<TInput>;
|
|
17
|
+
input: ArrayExpr<TInput>;
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
$range: [NumericExpr<TInput>, NumericExpr<TInput>, NumericExpr<TInput>?];
|
|
21
|
+
} | {
|
|
22
|
+
$reduce: {
|
|
23
|
+
in: Expr<TInput>;
|
|
24
|
+
initialValue: Expr<TInput>;
|
|
25
|
+
input: ArrayExpr<TInput>;
|
|
26
|
+
};
|
|
27
|
+
} | {
|
|
28
|
+
$reverseArray: ArrayExpr<TInput>;
|
|
29
|
+
} | {
|
|
30
|
+
$setDifference: [ArrayExpr<TInput>, ArrayExpr<TInput>];
|
|
31
|
+
} | {
|
|
32
|
+
$setIntersection: [ArrayExpr<TInput>, ArrayExpr<TInput>];
|
|
33
|
+
} | {
|
|
34
|
+
$setUnion: [ArrayExpr<TInput>, ArrayExpr<TInput>];
|
|
35
|
+
} | {
|
|
36
|
+
$slice: [ArrayExpr<TInput>, NumericExpr<TInput>, NumericExpr<TInput>?];
|
|
37
|
+
} | {
|
|
38
|
+
$zip: {
|
|
39
|
+
defaults?: ArrayExpr<TInput>;
|
|
40
|
+
inputs: ArrayExpr<TInput>[];
|
|
41
|
+
useLongestLength?: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type BooleanExpr<TInput extends object> = boolean | FieldRef<TInput> | {
|
|
45
|
+
$allElementsTrue: ArrayExpr<TInput>;
|
|
46
|
+
} | {
|
|
47
|
+
$and: ArrayExpr<TInput>;
|
|
48
|
+
} | {
|
|
49
|
+
$anyElementTrue: ArrayExpr<TInput>;
|
|
50
|
+
} | {
|
|
51
|
+
$eq: [Expr<TInput>, Expr<TInput>];
|
|
52
|
+
} | {
|
|
53
|
+
$gt: [Expr<TInput>, Expr<TInput>];
|
|
54
|
+
} | {
|
|
55
|
+
$gte: [Expr<TInput>, Expr<TInput>];
|
|
56
|
+
} | {
|
|
57
|
+
$in: [Expr<TInput>, ArrayExpr<TInput>];
|
|
58
|
+
} | {
|
|
59
|
+
$literal: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
$lt: [Expr<TInput>, Expr<TInput>];
|
|
62
|
+
} | {
|
|
63
|
+
$lte: [Expr<TInput>, Expr<TInput>];
|
|
64
|
+
} | {
|
|
65
|
+
$ne: [Expr<TInput>, Expr<TInput>];
|
|
66
|
+
} | {
|
|
67
|
+
$nin: [Expr<TInput>, ArrayExpr<TInput>];
|
|
68
|
+
} | {
|
|
69
|
+
$nor: Expr<TInput>[];
|
|
70
|
+
} | {
|
|
71
|
+
$not: Expr<TInput>;
|
|
72
|
+
} | {
|
|
73
|
+
$or: Expr<TInput>[];
|
|
74
|
+
} | {
|
|
75
|
+
$regexMatch: {
|
|
76
|
+
input: StringExpr<TInput>;
|
|
77
|
+
options?: StringExpr<TInput>;
|
|
78
|
+
regex: StringExpr<TInput>;
|
|
79
|
+
};
|
|
80
|
+
} | {
|
|
81
|
+
$setEquals: [ArrayExpr<TInput>, ArrayExpr<TInput>];
|
|
82
|
+
} | {
|
|
83
|
+
$setIsSubset: [ArrayExpr<TInput>, ArrayExpr<TInput>];
|
|
84
|
+
};
|
|
85
|
+
export interface ConditionalExpr<TInput extends object> {
|
|
86
|
+
$cond?: [
|
|
87
|
+
Expr<TInput>,
|
|
88
|
+
Expr<TInput>,
|
|
89
|
+
Expr<TInput>
|
|
90
|
+
] | {
|
|
91
|
+
else: Expr<TInput>;
|
|
92
|
+
if: Expr<TInput>;
|
|
93
|
+
then: Expr<TInput>;
|
|
94
|
+
};
|
|
95
|
+
$ifNull?: [Expr<TInput>, Expr<TInput>];
|
|
96
|
+
$switch: {
|
|
97
|
+
branches: {
|
|
98
|
+
case: Expr<TInput>;
|
|
99
|
+
then: Expr<TInput>;
|
|
100
|
+
}[];
|
|
101
|
+
default: Expr<TInput>;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export type DateExpr<TInput extends object> = Date | FieldRef<TInput> | {
|
|
105
|
+
$dateFromParts: {
|
|
106
|
+
day?: NumericExpr<TInput>;
|
|
107
|
+
hour?: NumericExpr<TInput>;
|
|
108
|
+
millisecond?: NumericExpr<TInput>;
|
|
109
|
+
minute?: NumericExpr<TInput>;
|
|
110
|
+
month?: NumericExpr<TInput>;
|
|
111
|
+
second?: NumericExpr<TInput>;
|
|
112
|
+
timezone?: StringExpr<TInput>;
|
|
113
|
+
year: NumericExpr<TInput>;
|
|
114
|
+
};
|
|
115
|
+
} | {
|
|
116
|
+
$dateFromString: {
|
|
117
|
+
dateString: StringExpr<TInput>;
|
|
118
|
+
format?: StringExpr<TInput>;
|
|
119
|
+
onError?: Expr<TInput>;
|
|
120
|
+
onNull?: Expr<TInput>;
|
|
121
|
+
timezone?: StringExpr<TInput>;
|
|
122
|
+
};
|
|
123
|
+
} | {
|
|
124
|
+
$literal: Date;
|
|
125
|
+
};
|
|
126
|
+
export interface DatePartsExpr<TInput extends object> {
|
|
127
|
+
$dateToParts: {
|
|
128
|
+
date: DateExpr<TInput>;
|
|
129
|
+
iso8601?: BooleanExpr<TInput>;
|
|
130
|
+
timezone?: StringExpr<TInput>;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export interface DateTimezoneExpr<TInput extends object> {
|
|
134
|
+
date: DateExpr<TInput>;
|
|
135
|
+
timezone: StringExpr<TInput>;
|
|
136
|
+
}
|
|
137
|
+
export type Expr<T extends object> = ArrayExpr<T> | BooleanExpr<T> | ConditionalExpr<T> | DateExpr<T> | DatePartsExpr<T> | NumericExpr<T> | StringExpr<T> | TypeExpr<T> | VariableExpr<T>;
|
|
138
|
+
export type FieldPaths<T extends object> = DotNotation<T> extends infer U ? U & string : never;
|
|
139
|
+
export type FieldRef<T extends object> = `$${FieldPaths<T>}`;
|
|
140
|
+
export type NumericExpr<TInput extends object> = FieldRef<TInput> | number | {
|
|
141
|
+
$abs: NumericExpr<TInput>;
|
|
142
|
+
} | {
|
|
143
|
+
$acos: NumericExpr<TInput>;
|
|
144
|
+
} | {
|
|
145
|
+
$acosh: NumericExpr<TInput>;
|
|
146
|
+
} | {
|
|
147
|
+
$add: (DateExpr<TInput> | NumericExpr<TInput>)[];
|
|
148
|
+
} | {
|
|
149
|
+
$asin: NumericExpr<TInput>;
|
|
150
|
+
} | {
|
|
151
|
+
$asinh: NumericExpr<TInput>;
|
|
152
|
+
} | {
|
|
153
|
+
$atan: NumericExpr<TInput>;
|
|
154
|
+
} | {
|
|
155
|
+
$atanh: NumericExpr<TInput>;
|
|
156
|
+
} | {
|
|
157
|
+
$ceil: NumericExpr<TInput>;
|
|
158
|
+
} | {
|
|
159
|
+
$convert: {
|
|
160
|
+
input: Expr<TInput>;
|
|
161
|
+
onError?: Expr<TInput>;
|
|
162
|
+
onNull?: Expr<TInput>;
|
|
163
|
+
to: NumericBsonType | {
|
|
164
|
+
type: NumericBsonType;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
} | {
|
|
168
|
+
$cos: NumericExpr<TInput>;
|
|
169
|
+
} | {
|
|
170
|
+
$cosh: NumericExpr<TInput>;
|
|
171
|
+
} | {
|
|
172
|
+
$dateDiff: {
|
|
173
|
+
endDate: DateExpr<TInput>;
|
|
174
|
+
startDate: DateExpr<TInput>;
|
|
175
|
+
timezone?: StringExpr<TInput>;
|
|
176
|
+
unit: StringExpr<TInput>;
|
|
177
|
+
};
|
|
178
|
+
} | {
|
|
179
|
+
$dayOfMonth?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
180
|
+
} | {
|
|
181
|
+
$dayOfWeek?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
182
|
+
} | {
|
|
183
|
+
$dayOfYear?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
184
|
+
} | {
|
|
185
|
+
$degreesToRadians: NumericExpr<TInput>;
|
|
186
|
+
} | {
|
|
187
|
+
$divide: [NumericExpr<TInput>, NumericExpr<TInput>];
|
|
188
|
+
} | {
|
|
189
|
+
$exp: NumericExpr<TInput>;
|
|
190
|
+
} | {
|
|
191
|
+
$floor: NumericExpr<TInput>;
|
|
192
|
+
} | {
|
|
193
|
+
$hour?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
194
|
+
} | {
|
|
195
|
+
$isoDayOfWeek?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
196
|
+
} | {
|
|
197
|
+
$isoWeek?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
198
|
+
} | {
|
|
199
|
+
$isoWeekYear?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
200
|
+
} | {
|
|
201
|
+
$literal: number;
|
|
202
|
+
} | {
|
|
203
|
+
$ln: NumericExpr<TInput>;
|
|
204
|
+
} | {
|
|
205
|
+
$log10: NumericExpr<TInput>;
|
|
206
|
+
} | {
|
|
207
|
+
$log: [NumericExpr<TInput>, NumericExpr<TInput>];
|
|
208
|
+
} | {
|
|
209
|
+
$millisecond?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
210
|
+
} | {
|
|
211
|
+
$minute?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
212
|
+
} | {
|
|
213
|
+
$mod: [NumericExpr<TInput>, NumericExpr<TInput>];
|
|
214
|
+
} | {
|
|
215
|
+
$month?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
216
|
+
} | {
|
|
217
|
+
$multiply: NumericExpr<TInput>[];
|
|
218
|
+
} | {
|
|
219
|
+
$pow: [NumericExpr<TInput>, NumericExpr<TInput>];
|
|
220
|
+
} | {
|
|
221
|
+
$radiansToDegrees: NumericExpr<TInput>;
|
|
222
|
+
} | {
|
|
223
|
+
$rand: Record<string, never>;
|
|
224
|
+
} | {
|
|
225
|
+
$round: [NumericExpr<TInput>, NumericExpr<TInput>] | NumericExpr<TInput>;
|
|
226
|
+
} | {
|
|
227
|
+
$second?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
228
|
+
} | {
|
|
229
|
+
$sin: NumericExpr<TInput>;
|
|
230
|
+
} | {
|
|
231
|
+
$sinh: NumericExpr<TInput>;
|
|
232
|
+
} | {
|
|
233
|
+
$size: ArrayExpr<TInput>;
|
|
234
|
+
} | {
|
|
235
|
+
$sqrt: NumericExpr<TInput>;
|
|
236
|
+
} | {
|
|
237
|
+
$strLenBytes: StringExpr<TInput>;
|
|
238
|
+
} | {
|
|
239
|
+
$strLenCP: StringExpr<TInput>;
|
|
240
|
+
} | {
|
|
241
|
+
$subtract: [DateExpr<TInput>, DateExpr<TInput>];
|
|
242
|
+
} | {
|
|
243
|
+
$subtract: [DateExpr<TInput> | NumericExpr<TInput>, NumericExpr<TInput>];
|
|
244
|
+
} | {
|
|
245
|
+
$tan: NumericExpr<TInput>;
|
|
246
|
+
} | {
|
|
247
|
+
$tanh: NumericExpr<TInput>;
|
|
248
|
+
} | {
|
|
249
|
+
$toDecimal: Expr<TInput>;
|
|
250
|
+
} | {
|
|
251
|
+
$toDouble: Expr<TInput>;
|
|
252
|
+
} | {
|
|
253
|
+
$toInt: Expr<TInput>;
|
|
254
|
+
} | {
|
|
255
|
+
$toLong: Expr<TInput>;
|
|
256
|
+
} | {
|
|
257
|
+
$trunc: [NumericExpr<TInput>, NumericExpr<TInput>] | NumericExpr<TInput>;
|
|
258
|
+
} | {
|
|
259
|
+
$week?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
260
|
+
} | {
|
|
261
|
+
$year?: DateExpr<TInput> | DateTimezoneExpr<TInput>;
|
|
262
|
+
};
|
|
263
|
+
export type StringExpr<TInput extends object> = FieldRef<TInput> | string | {
|
|
264
|
+
$concat: StringExpr<TInput>[];
|
|
265
|
+
} | {
|
|
266
|
+
$dateToString: {
|
|
267
|
+
date: DateExpr<TInput>;
|
|
268
|
+
format?: StringExpr<TInput>;
|
|
269
|
+
onNull?: Expr<TInput>;
|
|
270
|
+
timezone?: StringExpr<TInput>;
|
|
271
|
+
};
|
|
272
|
+
} | {
|
|
273
|
+
$literal: string;
|
|
274
|
+
} | {
|
|
275
|
+
$ltrim: {
|
|
276
|
+
chars?: StringExpr<TInput>;
|
|
277
|
+
input: StringExpr<TInput>;
|
|
278
|
+
};
|
|
279
|
+
} | {
|
|
280
|
+
$replaceAll: {
|
|
281
|
+
find: StringExpr<TInput>;
|
|
282
|
+
input: StringExpr<TInput>;
|
|
283
|
+
replacement: StringExpr<TInput>;
|
|
284
|
+
};
|
|
285
|
+
} | {
|
|
286
|
+
$replaceOne: {
|
|
287
|
+
find: StringExpr<TInput>;
|
|
288
|
+
input: StringExpr<TInput>;
|
|
289
|
+
replacement: StringExpr<TInput>;
|
|
290
|
+
};
|
|
291
|
+
} | {
|
|
292
|
+
$rtrim: {
|
|
293
|
+
chars?: StringExpr<TInput>;
|
|
294
|
+
input: StringExpr<TInput>;
|
|
295
|
+
};
|
|
296
|
+
} | {
|
|
297
|
+
$substr: [StringExpr<TInput>, NumericExpr<TInput>, NumericExpr<TInput>];
|
|
298
|
+
} | {
|
|
299
|
+
$substrBytes: [StringExpr<TInput>, NumericExpr<TInput>, NumericExpr<TInput>];
|
|
300
|
+
} | {
|
|
301
|
+
$substrCP: [StringExpr<TInput>, NumericExpr<TInput>, NumericExpr<TInput>];
|
|
302
|
+
} | {
|
|
303
|
+
$toLower: StringExpr<TInput>;
|
|
304
|
+
} | {
|
|
305
|
+
$toString: Expr<TInput>;
|
|
306
|
+
} | {
|
|
307
|
+
$toUpper: StringExpr<TInput>;
|
|
308
|
+
} | {
|
|
309
|
+
$trim: {
|
|
310
|
+
chars?: StringExpr<TInput>;
|
|
311
|
+
input: StringExpr<TInput>;
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
export interface TypeExpr<TInput extends object> {
|
|
315
|
+
$type?: Expr<TInput>;
|
|
316
|
+
}
|
|
317
|
+
export type VariableExpr<TInput extends object> = {
|
|
318
|
+
$let?: {
|
|
319
|
+
in: Expr<TInput>;
|
|
320
|
+
vars: Record<string, Expr<TInput>>;
|
|
321
|
+
};
|
|
322
|
+
} | {
|
|
323
|
+
$map?: {
|
|
324
|
+
as: string;
|
|
325
|
+
in: Expr<TInput>;
|
|
326
|
+
input: ArrayExpr<TInput>;
|
|
327
|
+
};
|
|
328
|
+
} | {
|
|
329
|
+
$reduce?: {
|
|
330
|
+
in: Expr<TInput>;
|
|
331
|
+
initialValue: Expr<TInput>;
|
|
332
|
+
input: ArrayExpr<TInput>;
|
|
333
|
+
};
|
|
334
|
+
};
|
package/dist/expr.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|