diff --git a/.gitmodules b/.gitmodules index 5f09a786..3f7efd4c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "packages/mql-typescript/mongo-php-library"] - path = packages/mql-typescript/mongo-php-library - url = https://github.com/mongodb-js/mongo-php-library +[submodule "packages/mql-typescript/mql-specifications"] + path = packages/mql-typescript/mql-specifications + url = https://github.com/mongodb/mql-specifications.git diff --git a/packages/mql-typescript/mongo-php-library b/packages/mql-typescript/mongo-php-library deleted file mode 160000 index 4a2867b1..00000000 --- a/packages/mql-typescript/mongo-php-library +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4a2867b1267c96190ccf7e813f21a9d7a00236cc diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications new file mode 160000 index 00000000..67983635 --- /dev/null +++ b/packages/mql-typescript/mql-specifications @@ -0,0 +1 @@ +Subproject commit 679836355dd5671b50b4a010698b659eb7e7107b diff --git a/packages/mql-typescript/out/schema.d.ts b/packages/mql-typescript/out/schema.d.ts index 9163ee0d..1335457a 100644 --- a/packages/mql-typescript/out/schema.d.ts +++ b/packages/mql-typescript/out/schema.d.ts @@ -33,7 +33,6 @@ export namespace Aggregation.Accumulator { export interface $accumulator { /** * Defines a custom accumulator function. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/} */ $accumulator: { @@ -107,7 +106,6 @@ export namespace Aggregation.Accumulator { export interface $bottom { /** * Returns the bottom element within a group according to the specified sort order. - * New in MongoDB 5.2: Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/} */ $bottom: { @@ -130,7 +128,6 @@ export namespace Aggregation.Accumulator { export interface $bottomN { /** * Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. - * New in MongoDB 5.2. * Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/} */ @@ -152,6 +149,24 @@ export namespace Aggregation.Accumulator { }; } + /** + * A type describing the `$concatArrays` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/} + */ + export interface $concatArrays { + /** + * Concatenates arrays to return the concatenated array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/} + */ + $concatArrays: [ + /** + * An array of expressions that resolve to an array. + * If any argument resolves to a value of null or refers to a field that is missing, `$concatArrays` returns `null`. + */ + ...ResolvesToArray[], + ]; + } + /** * A type describing the `$count` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/} @@ -160,7 +175,6 @@ export namespace Aggregation.Accumulator { /** * Returns the number of documents in the group or window. * Distinct from the $count pipeline stage. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/} */ $count: Record; @@ -173,7 +187,6 @@ export namespace Aggregation.Accumulator { export interface $covariancePop { /** * Returns the population covariance of two numeric expressions. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/} */ $covariancePop: [ @@ -189,7 +202,6 @@ export namespace Aggregation.Accumulator { export interface $covarianceSamp { /** * Returns the sample covariance of two numeric expressions. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/} */ $covarianceSamp: [ @@ -205,7 +217,6 @@ export namespace Aggregation.Accumulator { export interface $denseRank { /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. There are no gaps in the ranks. Ties receive the same rank. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/} */ $denseRank: Record; @@ -218,7 +229,6 @@ export namespace Aggregation.Accumulator { export interface $derivative { /** * Returns the average rate of change within the specified window. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/} */ $derivative: { @@ -239,7 +249,6 @@ export namespace Aggregation.Accumulator { export interface $documentNumber { /** * Returns the position of a document (known as the document number) in the $setWindowFields stage partition. Ties result in different adjacent document numbers. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/} */ $documentNumber: Record; @@ -252,7 +261,6 @@ export namespace Aggregation.Accumulator { export interface $expMovingAvg { /** * Returns the exponential moving average for the numeric expression. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/} */ $expMovingAvg: { @@ -317,7 +325,6 @@ export namespace Aggregation.Accumulator { export interface $integral { /** * Returns the approximation of the area under a curve. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/} */ $integral: { @@ -359,7 +366,7 @@ export namespace Aggregation.Accumulator { /** * An expression that resolves to the array from which to return n elements. */ - input: Expression; + input: ResolvesToArray; /** * An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. @@ -376,7 +383,6 @@ export namespace Aggregation.Accumulator { /** * Fills null and missing fields in a window using linear interpolation based on surrounding field values. * Available in the $setWindowFields stage. - * New in MongoDB 5.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/} */ $linearFill: ResolvesToNumber; @@ -390,7 +396,6 @@ export namespace Aggregation.Accumulator { /** * Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. * Available in the $setWindowFields stage. - * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/} */ $locf: Expression; @@ -438,7 +443,6 @@ export namespace Aggregation.Accumulator { export interface $median { /** * Returns an approximation of the median, the 50th percentile, as a scalar value. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -512,7 +516,6 @@ export namespace Aggregation.Accumulator { export interface $percentile { /** * Returns an array of scalar values that correspond to specified percentile values. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -558,12 +561,28 @@ export namespace Aggregation.Accumulator { export interface $rank { /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/} */ $rank: Record; } + /** + * A type describing the `$setUnion` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/} + */ + export interface $setUnion { + /** + * Takes two or more arrays and returns an array containing the elements that appear in any input array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/} + */ + $setUnion: [ + /** + * An array of expressions that resolve to an array. + */ + ...ResolvesToArray[], + ]; + } + /** * A type describing the `$shift` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/} @@ -571,7 +590,6 @@ export namespace Aggregation.Accumulator { export interface $shift { /** * Returns the value from an expression applied to a document in a specified position relative to the current document in the $setWindowFields stage partition. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/} */ $shift: { @@ -646,7 +664,6 @@ export namespace Aggregation.Accumulator { export interface $top { /** * Returns the top element within a group according to the specified sort order. - * New in MongoDB 5.2. * Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/} */ @@ -670,7 +687,6 @@ export namespace Aggregation.Accumulator { export interface $topN { /** * Returns an aggregation of the top n fields within a group, according to the specified sort order. - * New in MongoDB 5.2. * Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/} */ @@ -914,7 +930,6 @@ export namespace Aggregation.Expression { export interface $bitAnd { /** * Returns the result of a bitwise and operation on an array of int or long values. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/} */ $bitAnd: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -927,7 +942,6 @@ export namespace Aggregation.Expression { export interface $bitNot { /** * Returns the result of a bitwise not operation on a single argument or an array that contains a single int or long value. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/} */ $bitNot: ResolvesToInt | ResolvesToLong; @@ -940,7 +954,6 @@ export namespace Aggregation.Expression { export interface $bitOr { /** * Returns the result of a bitwise or operation on an array of int or long values. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/} */ $bitOr: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -953,7 +966,6 @@ export namespace Aggregation.Expression { export interface $bitXor { /** * Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/} */ $bitXor: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -1060,7 +1072,6 @@ export namespace Aggregation.Expression { export interface $convert { /** * Converts a value to a specified type. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/} */ $convert: { @@ -1105,6 +1116,18 @@ export namespace Aggregation.Expression { $cosh: ResolvesToNumber; } + /** + * A type describing the `$createObjectId` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/} + */ + export interface $createObjectId { + /** + * Returns a random object ID + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/} + */ + $createObjectId: Record; + } + /** * A type describing the `$dateAdd` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/} @@ -1621,7 +1644,6 @@ export namespace Aggregation.Expression { export interface $function { /** * Defines a custom function. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/} */ $function: { @@ -1646,7 +1668,6 @@ export namespace Aggregation.Expression { export interface $getField { /** * Returns the value of a specified field from a document. You can use $getField to retrieve the value of fields with names that contain periods (.) or start with dollar signs ($). - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/} */ $getField: { @@ -1868,7 +1889,6 @@ export namespace Aggregation.Expression { /** * Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. * Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/} */ $isNumber: Expression; @@ -1954,12 +1974,12 @@ export namespace Aggregation.Expression { /** * A type describing the `$lastN` operator. - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/} */ export interface $lastN { /** * Returns a specified number of elements from the end of an array. - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/} */ $lastN: { /** @@ -1989,7 +2009,7 @@ export namespace Aggregation.Expression { * Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. */ - vars: ExpressionMap; + vars: Record; /** * The expression to evaluate. @@ -2088,7 +2108,6 @@ export namespace Aggregation.Expression { export interface $ltrim { /** * Removes whitespace or the specified characters from the beginning of a string. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/} */ $ltrim: { @@ -2175,7 +2194,6 @@ export namespace Aggregation.Expression { export interface $median { /** * Returns an approximation of the median, the 50th percentile, as a scalar value. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -2416,7 +2434,6 @@ export namespace Aggregation.Expression { export interface $percentile { /** * Returns an array of scalar values that correspond to specified percentile values. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -2533,33 +2550,19 @@ export namespace Aggregation.Expression { * - value is the variable that represents the cumulative value of the expression. * - this is the variable that refers to the element being processed. */ - in: - | Expression< - S & { - /** - * The variable that represents the cumulative value of the expression. - */ - $this: any; - - /** - * The variable that refers to the element being processed. - */ - $value: any; - } - > - | ExpressionMap< - S & { - /** - * The variable that represents the cumulative value of the expression. - */ - $this: any; - - /** - * The variable that refers to the element being processed. - */ - $value: any; - } - >; + in: Expression< + S & { + /** + * The variable that refers to the element being processed. + */ + $this: any; + + /** + * The variable that represents the cumulative value of the expression. + */ + $value: any; + } + >; }; } @@ -2570,7 +2573,6 @@ export namespace Aggregation.Expression { export interface $regexFind { /** * Applies a regular expression (regex) to a string and returns information on the first matched substring. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/} */ $regexFind: { @@ -2594,7 +2596,6 @@ export namespace Aggregation.Expression { export interface $regexFindAll { /** * Applies a regular expression (regex) to a string and returns information on the all matched substrings. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/} */ $regexFindAll: { @@ -2618,7 +2619,6 @@ export namespace Aggregation.Expression { export interface $regexMatch { /** * Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/} */ $regexMatch: { @@ -2643,7 +2643,6 @@ export namespace Aggregation.Expression { /** * Replaces all instances of a search string in an input string with a replacement string. * $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/} */ $replaceAll: { @@ -2655,7 +2654,7 @@ export namespace Aggregation.Expression { /** * The string to search for within the given input. Can be any valid expression that resolves to a string or a null. If find refers to a field that is missing, $replaceAll returns null. */ - find: ResolvesToString | ResolvesToNull; + find: ResolvesToString | ResolvesToNull | ResolvesToRegex; /** * The string to use to replace all matched instances of find in input. Can be any valid expression that resolves to a string or a null. @@ -2671,7 +2670,6 @@ export namespace Aggregation.Expression { export interface $replaceOne { /** * Replaces the first instance of a matched string in a given input. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/} */ $replaceOne: { @@ -2814,7 +2812,6 @@ export namespace Aggregation.Expression { export interface $setField { /** * Adds, updates, or removes a specified field in a document. You can use $setField to add, update, or remove fields with names that contain periods (.) or start with dollar signs ($). - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/} */ $setField: { @@ -2998,7 +2995,7 @@ export namespace Aggregation.Expression { /** * The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. */ - delimiter: ResolvesToString, + delimiter: ResolvesToString | ResolvesToRegex, ]; } @@ -3237,7 +3234,6 @@ export namespace Aggregation.Expression { export interface $toBool { /** * Converts value to a boolean. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/} */ $toBool: Expression; @@ -3250,7 +3246,6 @@ export namespace Aggregation.Expression { export interface $toDate { /** * Converts value to a Date. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/} */ $toDate: Expression; @@ -3263,7 +3258,6 @@ export namespace Aggregation.Expression { export interface $toDecimal { /** * Converts value to a Decimal128. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/} */ $toDecimal: Expression; @@ -3276,7 +3270,6 @@ export namespace Aggregation.Expression { export interface $toDouble { /** * Converts value to a double. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/} */ $toDouble: Expression; @@ -3301,7 +3294,6 @@ export namespace Aggregation.Expression { export interface $toInt { /** * Converts value to an integer. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/} */ $toInt: Expression; @@ -3314,7 +3306,6 @@ export namespace Aggregation.Expression { export interface $toLong { /** * Converts value to a long. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/} */ $toLong: Expression; @@ -3339,7 +3330,6 @@ export namespace Aggregation.Expression { export interface $toObjectId { /** * Converts value to an ObjectId. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/} */ $toObjectId: Expression; @@ -3352,7 +3342,6 @@ export namespace Aggregation.Expression { export interface $toString { /** * Converts value to a string. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/} */ $toString: Expression; @@ -3377,7 +3366,6 @@ export namespace Aggregation.Expression { export interface $trim { /** * Removes whitespace or the specified characters from the beginning and end of a string. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/} */ $trim: { @@ -3425,7 +3413,6 @@ export namespace Aggregation.Expression { export interface $tsIncrement { /** * Returns the incrementing ordinal from a timestamp as a long. - * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/} */ $tsIncrement: ResolvesToTimestamp; @@ -3438,7 +3425,6 @@ export namespace Aggregation.Expression { export interface $tsSecond { /** * Returns the seconds from a timestamp as a long. - * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/} */ $tsSecond: ResolvesToTimestamp; @@ -3664,6 +3650,18 @@ export namespace Aggregation.Query { $centerSphere: unknown[]; } + /** + * A type describing the `$comment` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/} + */ + export interface $comment { + /** + * Adds a comment to a query predicate. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/} + */ + $comment: string; + } + /** * A type describing the `$elemMatch` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/} @@ -3685,7 +3683,7 @@ export namespace Aggregation.Query { * Matches values that are equal to a specified value. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/} */ - $eq: Expression; + $eq: any; } /** @@ -4499,7 +4497,6 @@ export namespace Aggregation.Stage { /** * Specifies whether to include additional change events, such as such as DDL and index operations. - * New in MongoDB 6.0. */ showExpandedEvents?: boolean; @@ -4796,7 +4793,7 @@ export namespace Aggregation.Stage { /** * The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. */ - _id: Expression | ExpressionMap; + _id: Expression; }, /** * Computed using the accumulator operators. @@ -4944,7 +4941,7 @@ export namespace Aggregation.Stage { * The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. * The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages. */ - pipeline?: UntypedPipeline; + pipeline?: Pipeline; /** * Specifies the name of the new array field to add to the input documents. The new array field contains the matching documents from the from collection. If the specified name already exists in the input document, the existing field is overwritten. @@ -4972,7 +4969,6 @@ export namespace Aggregation.Stage { export interface $merge { /** * Writes the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the $merge stage, it must be the last stage in the pipeline. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/} */ $merge: { @@ -4994,7 +4990,7 @@ export namespace Aggregation.Stage { /** * The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). */ - whenMatched?: WhenMatched | UntypedPipeline; + whenMatched?: WhenMatched | Pipeline; /** * The behavior of $merge if a result document does not match an existing document in the out collection. @@ -5036,9 +5032,7 @@ export namespace Aggregation.Stage { * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/} */ - $project: {} & { - [specification: string]: Expression | ExpressionMap; - }; + $project: {} & { [specification: string]: Expression }; } /** @@ -5095,6 +5089,38 @@ export namespace Aggregation.Stage { }; } + /** + * A type describing the `$scoreFusion` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/} + */ + export interface $scoreFusion { + /** + * Combines multiple pipelines using relative score fusion to create hybrid search results. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/} + */ + $scoreFusion: { + /** + * An object with the following required fields: + * - input.pipelines: Map from name to input pipeline. Each pipeline must be operating on the same collection. Minimum of one pipeline. + * - input.normalization: Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler. + */ + input: Record; + + /** + * An object with the following optional fields: + * - combination.weights: Map from pipeline name to numbers (non-negative). If unspecified, default weight is 1 for each pipeline. + * - combination.method: Specifies method for combining scores. Value can be avg or expression. Default is avg. + * - combination.expression: This is the custom expression that is used when combination.method is set to expression. + */ + combination?: Record; + + /** + * Set to true to include detailed scoring information. + */ + scoreDetails: boolean; + }; + } + /** * A type describing the `$search` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/} @@ -5114,7 +5140,7 @@ export namespace Aggregation.Stage { /** * Specifies the highlighting options for displaying search terms in their original context. */ - highlight?: SearchHighlight; + highlight?: Record; /** * Parallelize search across segments on dedicated search nodes. @@ -5203,7 +5229,6 @@ export namespace Aggregation.Stage { export interface $setWindowFields { /** * Groups documents into windows and applies one or more operators to the documents in each window. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/} */ $setWindowFields: { @@ -5232,7 +5257,6 @@ export namespace Aggregation.Stage { export interface $shardedDataDistribution { /** * Provides data and size distribution information on sharded collections. - * New in MongoDB 6.0.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/} */ $shardedDataDistribution: Record; @@ -5281,7 +5305,6 @@ export namespace Aggregation.Stage { export interface $unionWith { /** * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/} */ $unionWith: { @@ -5294,7 +5317,7 @@ export namespace Aggregation.Stage { * An aggregation pipeline to apply to the specified coll. * The pipeline cannot include the $out and $merge stages. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. */ - pipeline?: UntypedPipeline; + pipeline?: Pipeline; }; } @@ -5388,12 +5411,207 @@ export namespace Aggregation.Stage { }; } } +export namespace Aggregation.Update { + /** + * A type describing the `$addToSet` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/addToSet/} + */ + export interface $addToSet { + /** + * Adds a value to an array unless the value is already present. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/addToSet/} + */ + $addToSet: {} & { [field: string]: any }; + } + + /** + * A type describing the `$bit` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/bit/} + */ + export interface $bit { + /** + * Performs bitwise updates of integer values. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/bit/} + */ + $bit: { + /** + * Each field maps to an object containing exactly one bitwise operation: + * and, or, or xor. + */ + } & { [field: string]: BitwiseOperation }; + } + + /** + * A type describing the `$currentDate` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/} + */ + export interface $currentDate { + /** + * Sets the value of a field to the current date as either a Date or Timestamp. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/} + */ + $currentDate: { + /** + * The value for each field can be either: + * - true, to set the field to the current date. + * - a document with $type set to "date" or "timestamp". + */ + } & { [field: string]: boolean | Record }; + } + + /** + * A type describing the `$inc` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/inc/} + */ + export interface $inc { + /** + * Increments a field by the specified numeric amount. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/inc/} + */ + $inc: {} & { [field: string]: Number }; + } + + /** + * A type describing the `$max` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/max/} + */ + export interface $max { + /** + * Updates a field only if the specified value is greater than the current field value. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/max/} + */ + $max: {} & { [field: string]: any }; + } + + /** + * A type describing the `$min` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/min/} + */ + export interface $min { + /** + * Updates a field only if the specified value is less than the current field value. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/min/} + */ + $min: {} & { [field: string]: any }; + } + + /** + * A type describing the `$mul` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/mul/} + */ + export interface $mul { + /** + * Multiplies the value of a field by the specified number. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/mul/} + */ + $mul: {} & { [field: string]: Number }; + } + + /** + * A type describing the `$pop` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pop/} + */ + export interface $pop { + /** + * Removes the first or last element of an array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pop/} + */ + $pop: {} & { [field: string]: Int }; + } + + /** + * A type describing the `$pull` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pull/} + */ + export interface $pull { + /** + * Removes all array elements that match a specified value or condition. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pull/} + */ + $pull: {} & { [field: string]: any }; + } + + /** + * A type describing the `$pullAll` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pullAll/} + */ + export interface $pullAll { + /** + * Removes all matching values from an array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pullAll/} + */ + $pullAll: {} & { [field: string]: unknown[] }; + } + + /** + * A type describing the `$push` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/push/} + */ + export interface $push { + /** + * Appends a specified value to an array, with optional modifiers. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/push/} + */ + $push: {} & { [field: string]: any }; + } + + /** + * A type describing the `$rename` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/rename/} + */ + export interface $rename { + /** + * Renames a field. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/rename/} + */ + $rename: {} & { [field: string]: string }; + } + + /** + * A type describing the `$set` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/set/} + */ + export interface $set { + /** + * Sets the value of a field. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/set/} + */ + $set: {} & { [field: string]: any }; + } + + /** + * A type describing the `$setOnInsert` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/} + */ + export interface $setOnInsert { + /** + * Sets the value of a field if an update with upsert creates a new document. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/} + */ + $setOnInsert: {} & { [field: string]: any }; + } + + /** + * A type describing the `$unset` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/unset/} + */ + export interface $unset { + /** + * Removes the specified field from a document. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/unset/} + */ + $unset: {} & { [field: string]: any }; + } +} -export type Int = number | bson.Int32; -export type Double = number | bson.Double; -export type Decimal = bson.Decimal128; -export type Regex = RegExp | bson.BSONRegExp; -export type Long = bigint | bson.Long; +export type Int = number | bson.Int32 | { $numberInt: string }; +export type Double = number | bson.Double | { $numberDouble: string }; +export type Decimal = bson.Decimal128 | { $numberDecimal: string }; +export type Regex = + | RegExp + | bson.BSONRegExp + | { pattern: string; options?: string }; +export type Long = bigint | bson.Long | { $numberLong: string }; export type Javascript = bson.Code | Function | string; export type Geometry = | { type: 'Point'; coordinates: number[] } @@ -5423,6 +5641,10 @@ export type SearchPath = | UnprefixedFieldPath | UnprefixedFieldPath[] | { wildcard: string }; +export type BitwiseOperation = + | { and: Int | Long } + | { or: Int | Long } + | { xor: Int | Long }; export type SearchScore = unknown; export type Granularity = string; export type FullDocument = string; @@ -5487,6 +5709,7 @@ export type Stage = | Aggregation.Stage.$replaceRoot | Aggregation.Stage.$replaceWith | Aggregation.Stage.$sample + | Aggregation.Stage.$scoreFusion | Aggregation.Stage.$search | Aggregation.Stage.$searchMeta | Aggregation.Stage.$set @@ -5505,6 +5728,7 @@ export type Query = | QueryOperator | Partial<{ [k in keyof S]: Condition }> | Aggregation.Query.$and + | Aggregation.Query.$comment | Aggregation.Query.$expr | Aggregation.Query.$jsonSchema | Aggregation.Query.$nor @@ -5518,6 +5742,7 @@ export type Accumulator = | Aggregation.Accumulator.$avg | Aggregation.Accumulator.$bottom | Aggregation.Accumulator.$bottomN + | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$count | Aggregation.Accumulator.$first | Aggregation.Accumulator.$firstN @@ -5531,6 +5756,7 @@ export type Accumulator = | Aggregation.Accumulator.$minN | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push + | Aggregation.Accumulator.$setUnion | Aggregation.Accumulator.$stdDevPop | Aggregation.Accumulator.$stdDevSamp | Aggregation.Accumulator.$sum @@ -5646,6 +5872,8 @@ export type ResolvesToArray = | ResolvesToAny | ArrayFieldPath | unknown[] + | Aggregation.Accumulator.$concatArrays + | Aggregation.Accumulator.$setUnion | Aggregation.Expression.$concatArrays | Aggregation.Expression.$filter | Aggregation.Expression.$firstN @@ -5673,6 +5901,7 @@ export type ResolvesToObjectId = | ResolvesToAny | ObjectIdFieldPath | bson.ObjectId + | Aggregation.Expression.$createObjectId | Aggregation.Expression.$toObjectId; export type ResolvesToBool = | ResolvesToAny @@ -5804,6 +6033,7 @@ export type AccumulatorOperator = | Aggregation.Accumulator.$avg | Aggregation.Accumulator.$bottom | Aggregation.Accumulator.$bottomN + | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$count | Aggregation.Accumulator.$covariancePop | Aggregation.Accumulator.$covarianceSamp @@ -5827,6 +6057,7 @@ export type AccumulatorOperator = | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push | Aggregation.Accumulator.$rank + | Aggregation.Accumulator.$setUnion | Aggregation.Accumulator.$shift | Aggregation.Accumulator.$stdDevPop | Aggregation.Accumulator.$stdDevSamp @@ -5838,6 +6069,7 @@ export type Window = | Aggregation.Accumulator.$avg | Aggregation.Accumulator.$bottom | Aggregation.Accumulator.$bottomN + | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$count | Aggregation.Accumulator.$covariancePop | Aggregation.Accumulator.$covarianceSamp @@ -5860,6 +6092,7 @@ export type Window = | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push | Aggregation.Accumulator.$rank + | Aggregation.Accumulator.$setUnion | Aggregation.Accumulator.$shift | Aggregation.Accumulator.$stdDevPop | Aggregation.Accumulator.$stdDevSamp @@ -5895,6 +6128,7 @@ export type ExpressionOperator = | Aggregation.Expression.$convert | Aggregation.Expression.$cos | Aggregation.Expression.$cosh + | Aggregation.Expression.$createObjectId | Aggregation.Expression.$dateAdd | Aggregation.Expression.$dateDiff | Aggregation.Expression.$dateFromParts @@ -6071,6 +6305,7 @@ export type QueryOperator = | Aggregation.Query.$box | Aggregation.Query.$center | Aggregation.Query.$centerSphere + | Aggregation.Query.$comment | Aggregation.Query.$elemMatch | Aggregation.Query.$eq | Aggregation.Query.$exists @@ -6152,6 +6387,7 @@ export type StageOperator = | Aggregation.Stage.$replaceRoot | Aggregation.Stage.$replaceWith | Aggregation.Stage.$sample + | Aggregation.Stage.$scoreFusion | Aggregation.Stage.$search | Aggregation.Stage.$searchMeta | Aggregation.Stage.$set @@ -6164,3 +6400,35 @@ export type StageOperator = | Aggregation.Stage.$unset | Aggregation.Stage.$unwind | Aggregation.Stage.$vectorSearch; +export type Update = + | Aggregation.Update.$addToSet + | Aggregation.Update.$bit + | Aggregation.Update.$currentDate + | Aggregation.Update.$inc + | Aggregation.Update.$max + | Aggregation.Update.$min + | Aggregation.Update.$mul + | Aggregation.Update.$pop + | Aggregation.Update.$pull + | Aggregation.Update.$pullAll + | Aggregation.Update.$push + | Aggregation.Update.$rename + | Aggregation.Update.$set + | Aggregation.Update.$setOnInsert + | Aggregation.Update.$unset; +export type UpdateOperator = + | Aggregation.Update.$addToSet + | Aggregation.Update.$bit + | Aggregation.Update.$currentDate + | Aggregation.Update.$inc + | Aggregation.Update.$max + | Aggregation.Update.$min + | Aggregation.Update.$mul + | Aggregation.Update.$pop + | Aggregation.Update.$pull + | Aggregation.Update.$pullAll + | Aggregation.Update.$push + | Aggregation.Update.$rename + | Aggregation.Update.$set + | Aggregation.Update.$setOnInsert + | Aggregation.Update.$unset; diff --git a/packages/mql-typescript/package.json b/packages/mql-typescript/package.json index f7d55363..ae781580 100644 --- a/packages/mql-typescript/package.json +++ b/packages/mql-typescript/package.json @@ -57,7 +57,7 @@ "check-ci": "npm run check", "test": "tsc --noEmit tests/**/*.ts", "reformat": "npm run prettier -- --write .", - "extract-metaschema": "json-refs resolve mongo-php-library/generator/config/schema.json | json-schema-to-zod -n Operator -o src/metaschema.ts && npm run prettier -- --write src/metaschema.ts", + "extract-metaschema": "json-refs resolve mql-specifications/schema.json | json-schema-to-zod -n Operator -o src/metaschema.ts && npm run prettier -- --write src/metaschema.ts", "pregenerate-schema": "npm run extract-metaschema", "generate-schema": "ts-node src/cli.ts schema", "postgenerate-schema": "npm run prettier -- --write out/*", @@ -66,7 +66,7 @@ "postgenerate-tests": "npm run prettier -- --write tests/**/*.ts", "pregenerate-driver-schema": "npm run extract-metaschema", "generate-driver-schema": "ts-node src/cli.ts driver-schema", - "postgenerate-driver-schema": "yamlfix -c mongo-php-library/generator/config/.yamlfix.toml mongo-php-library/generator/config", + "postgenerate-driver-schema": "yamlfix -c mql-specifications/.yamlfix.toml mql-specifications/definitions", "format-generated-files": "npm run postgenerate-schema && npm run postgenerate-tests && npm run postgenerate-driver-schema" }, "devDependencies": { diff --git a/packages/mql-typescript/src/generator.ts b/packages/mql-typescript/src/generator.ts index a8591d3e..763cc91b 100644 --- a/packages/mql-typescript/src/generator.ts +++ b/packages/mql-typescript/src/generator.ts @@ -196,9 +196,8 @@ export abstract class GeneratorBase { protected configDir = path.join( __dirname, '..', - 'mongo-php-library', - 'generator', - 'config', + 'mql-specifications', + 'definitions', ); private async *listCategories( diff --git a/packages/mql-typescript/src/metaschema.ts b/packages/mql-typescript/src/metaschema.ts index d8b44d46..c680d316 100644 --- a/packages/mql-typescript/src/metaschema.ts +++ b/packages/mql-typescript/src/metaschema.ts @@ -3,12 +3,14 @@ import { z } from 'zod'; export const Operator = z .object({ name: z.string().regex(new RegExp('^\\$?[a-z][a-zA-Z0-9]*$')), + minVersion: z.string().regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[0-9]+)?$')), link: z.string().url().regex(new RegExp('^https://')), type: z.array( z.enum([ 'accumulator', 'stage', 'query', + 'update', 'fieldQuery', 'filter', 'window', @@ -42,22 +44,22 @@ export const Operator = z z .object({ name: z.string().regex(new RegExp('^([_$]?[a-z][a-zA-Z0-9]*|N)$')), + minVersion: z + .string() + .regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[0-9]+)?$')) + .optional(), type: z.array( z.enum([ 'accumulator', 'query', 'fieldQuery', 'pipeline', - 'untypedPipeline', 'window', 'expression', - 'expressionMap', 'geometry', - 'fieldPath', 'unprefixedFieldPath', 'timeUnit', 'sortSpec', - 'any', 'granularity', 'fullDocument', 'fullDocumentBeforeChange', @@ -68,6 +70,9 @@ export const Operator = z 'range', 'sortBy', 'geoPoint', + 'resolvesToAny', + 'fieldPath', + 'any', 'resolvesToNumber', 'numberFieldPath', 'number', @@ -118,8 +123,8 @@ export const Operator = z 'decimal', 'searchPath', 'searchScore', + 'bitwiseOperation', 'searchOperator', - 'searchHighlight', ]), ), description: z.string().optional(), @@ -135,7 +140,7 @@ export const Operator = z syntheticVariables: z .array( z.object({ - name: z.string().regex(new RegExp('^[$]?[a-zA-Z0-9]*$')), + name: z.string().regex(new RegExp('^[$]?[a-zA-Z0-9]+$')), description: z.string().optional(), }), ) @@ -148,12 +153,13 @@ export const Operator = z .array( z .object({ - name: z.string(), + name: z.string().optional(), link: z.string().url().regex(new RegExp('^https://')).optional(), - pipeline: z.array(z.record(z.any())), + pipeline: z.array(z.record(z.any())).optional(), + filter: z.record(z.any()).optional(), + update: z.record(z.any()).optional(), schema: z .union([ - z.string(), z.record( z.record( z @@ -206,10 +212,12 @@ export const Operator = z .strict(), ), ), + z.string(), ]) .optional(), }) - .strict(), + .strict() + .and(z.union([z.any(), z.any()])), ) .optional(), }) diff --git a/packages/mql-typescript/src/schema-generator.ts b/packages/mql-typescript/src/schema-generator.ts index aa7d129a..da008079 100644 --- a/packages/mql-typescript/src/schema-generator.ts +++ b/packages/mql-typescript/src/schema-generator.ts @@ -86,6 +86,9 @@ export class SchemaGenerator extends GeneratorBase { 'UnprefixedFieldPath[]', '{ wildcard: string }', ], + bitwiseOperation: [ + '({ and: Int | Long } | { or: Int | Long } | { xor: Int | Long })', + ], searchScore: ['unknown'], granularity: ['string'], fullDocument: ['string'],