From acfe2aca769647793691a01502cfe206312bdbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 24 Jan 2025 11:03:41 +0100 Subject: [PATCH] PHPLIB-1598 Use named types for enums (#1570) --- generator/config/accumulator/bottom.yaml | 2 +- generator/config/accumulator/bottomN.yaml | 2 +- generator/config/accumulator/median.yaml | 2 +- generator/config/accumulator/percentile.yaml | 2 +- generator/config/accumulator/top.yaml | 2 +- generator/config/accumulator/topN.yaml | 2 +- generator/config/expression/median.yaml | 2 +- generator/config/expression/percentile.yaml | 2 +- generator/config/expression/sortArray.yaml | 2 +- generator/config/expressions.php | 29 +++++++------------- generator/config/schema.json | 12 +++++++- generator/config/stage/bucketAuto.yaml | 2 +- generator/config/stage/changeStream.yaml | 4 +-- generator/config/stage/densify.yaml | 2 +- generator/config/stage/fill.yaml | 2 +- generator/config/stage/geoNear.yaml | 2 +- generator/config/stage/merge.yaml | 6 ++-- generator/config/stage/out.yaml | 2 +- generator/config/stage/setWindowFields.yaml | 2 +- src/Builder/Stage/BucketAutoStage.php | 8 +++--- src/Builder/Stage/FactoryTrait.php | 4 +-- src/Builder/Stage/FluentFactoryTrait.php | 4 +-- 22 files changed, 49 insertions(+), 48 deletions(-) diff --git a/generator/config/accumulator/bottom.yaml b/generator/config/accumulator/bottom.yaml index 4ebb897ea..1e363d193 100644 --- a/generator/config/accumulator/bottom.yaml +++ b/generator/config/accumulator/bottom.yaml @@ -12,7 +12,7 @@ arguments: - name: sortBy type: - - object # SortSpec + - sortBy description: | Specifies the order of results, with syntax similar to $sort. - diff --git a/generator/config/accumulator/bottomN.yaml b/generator/config/accumulator/bottomN.yaml index 30bca678c..355d8e09a 100644 --- a/generator/config/accumulator/bottomN.yaml +++ b/generator/config/accumulator/bottomN.yaml @@ -19,7 +19,7 @@ arguments: - name: sortBy type: - - object # SortSpec + - sortBy description: | Specifies the order of results, with syntax similar to $sort. - diff --git a/generator/config/accumulator/median.yaml b/generator/config/accumulator/median.yaml index 708ea3502..e743c6982 100644 --- a/generator/config/accumulator/median.yaml +++ b/generator/config/accumulator/median.yaml @@ -22,7 +22,7 @@ arguments: - name: method type: - - string # AccumulatorPercentile + - accumulatorPercentile description: | The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. tests: diff --git a/generator/config/accumulator/percentile.yaml b/generator/config/accumulator/percentile.yaml index b2a6147d4..b3c41b0e4 100644 --- a/generator/config/accumulator/percentile.yaml +++ b/generator/config/accumulator/percentile.yaml @@ -32,7 +32,7 @@ arguments: - name: method type: - - string # AccumulatorPercentile + - accumulatorPercentile description: | The method that mongod uses to calculate the percentile value. The method must be 'approximate'. tests: diff --git a/generator/config/accumulator/top.yaml b/generator/config/accumulator/top.yaml index 2f4deefa2..94923cccd 100644 --- a/generator/config/accumulator/top.yaml +++ b/generator/config/accumulator/top.yaml @@ -13,7 +13,7 @@ arguments: - name: sortBy type: - - object # SortSpec + - sortBy description: | Specifies the order of results, with syntax similar to $sort. - diff --git a/generator/config/accumulator/topN.yaml b/generator/config/accumulator/topN.yaml index c8073e09f..c5eff6056 100644 --- a/generator/config/accumulator/topN.yaml +++ b/generator/config/accumulator/topN.yaml @@ -19,7 +19,7 @@ arguments: - name: sortBy type: - - object # SortSpec + - sortBy description: | Specifies the order of results, with syntax similar to $sort. - diff --git a/generator/config/expression/median.yaml b/generator/config/expression/median.yaml index 2708f7f16..2aac26a1f 100644 --- a/generator/config/expression/median.yaml +++ b/generator/config/expression/median.yaml @@ -22,7 +22,7 @@ arguments: - name: method type: - - string # AccumulatorPercentile + - accumulatorPercentile description: | The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. tests: diff --git a/generator/config/expression/percentile.yaml b/generator/config/expression/percentile.yaml index 8c601cc83..b19fc1904 100644 --- a/generator/config/expression/percentile.yaml +++ b/generator/config/expression/percentile.yaml @@ -32,7 +32,7 @@ arguments: - name: method type: - - string # AccumulatorPercentile + - accumulatorPercentile description: | The method that mongod uses to calculate the percentile value. The method must be 'approximate'. tests: diff --git a/generator/config/expression/sortArray.yaml b/generator/config/expression/sortArray.yaml index 962ebf1ce..d558f2233 100644 --- a/generator/config/expression/sortArray.yaml +++ b/generator/config/expression/sortArray.yaml @@ -18,9 +18,9 @@ arguments: - name: sortBy type: - - object # SortSpec - int - sortSpec + - sortBy description: | The document specifies a sort ordering. tests: diff --git a/generator/config/expressions.php b/generator/config/expressions.php index a2c649e8e..f77b45e79 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -131,45 +131,36 @@ ], // @todo add enum values - 'Granularity' => [ + 'granularity' => [ 'acceptedTypes' => [...$bsonTypes['string']], ], - 'FullDocument' => [ + 'fullDocument' => [ 'acceptedTypes' => [...$bsonTypes['string']], ], - 'FullDocumentBeforeChange' => [ + 'fullDocumentBeforeChange' => [ 'acceptedTypes' => [...$bsonTypes['string']], ], - 'AccumulatorPercentile' => [ + 'accumulatorPercentile' => [ 'acceptedTypes' => [...$bsonTypes['string']], ], - 'WhenMatched' => [ + 'whenMatched' => [ 'acceptedTypes' => [...$bsonTypes['string']], ], - 'WhenNotMatched' => [ + 'whenNotMatched' => [ 'acceptedTypes' => [...$bsonTypes['string']], ], // @todo create specific model classes factories - 'OutCollection' => [ + 'outCollection' => [ 'acceptedTypes' => [...$bsonTypes['object']], ], - 'CollStats' => [ + 'range' => [ 'acceptedTypes' => [...$bsonTypes['object']], ], - 'Range' => [ + 'sortBy' => [ 'acceptedTypes' => [...$bsonTypes['object']], ], - 'FillOut' => [ - 'acceptedTypes' => [...$bsonTypes['object']], - ], - 'SortSpec' => [ - 'acceptedTypes' => [...$bsonTypes['object']], - ], - 'Window' => [ - 'acceptedTypes' => [...$bsonTypes['object']], - ], - 'GeoPoint' => [ + 'geoPoint' => [ 'acceptedTypes' => [...$bsonTypes['object']], ], diff --git a/generator/config/schema.json b/generator/config/schema.json index c92e6ddb7..63739ebcb 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -9,7 +9,7 @@ "name": { "$comment": "The name of the operator. Must start with a $", "type": "string", - "pattern": "^\\$[a-z0-9][a-zA-Z0-9]*$" + "pattern": "^\\$?[a-z][a-zA-Z0-9]*$" }, "link": { "$comment": "The link to the operator's documentation on MongoDB's website.", @@ -122,6 +122,16 @@ "timeUnit", "sortSpec", "any", + "granularity", + "fullDocument", + "fullDocumentBeforeChange", + "accumulatorPercentile", + "whenMatched", + "whenNotMatched", + "outCollection", + "range", + "sortBy", + "geoPoint", "resolvesToNumber", "numberFieldPath", "number", "resolvesToDouble", "doubleFieldPath", "double", "resolvesToString", "stringFieldPath", "string", diff --git a/generator/config/stage/bucketAuto.yaml b/generator/config/stage/bucketAuto.yaml index 48c102e11..73775fde8 100644 --- a/generator/config/stage/bucketAuto.yaml +++ b/generator/config/stage/bucketAuto.yaml @@ -30,7 +30,7 @@ arguments: - name: granularity type: - - object # Granularity + - granularity optional: true description: | A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. diff --git a/generator/config/stage/changeStream.yaml b/generator/config/stage/changeStream.yaml index 44fdb3c5c..be413ef5d 100644 --- a/generator/config/stage/changeStream.yaml +++ b/generator/config/stage/changeStream.yaml @@ -17,14 +17,14 @@ arguments: - name: fullDocument type: - - string # FullDocument + - fullDocument optional: true description: | Specifies whether change notifications include a copy of the full document when modified by update operations. - name: fullDocumentBeforeChange type: - - string # FullDocumentBeforeChange + - fullDocumentBeforeChange optional: true description: | Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. diff --git a/generator/config/stage/densify.yaml b/generator/config/stage/densify.yaml index a66cf18dd..46ccbd6dd 100644 --- a/generator/config/stage/densify.yaml +++ b/generator/config/stage/densify.yaml @@ -25,7 +25,7 @@ arguments: - name: range type: - - object # Range + - range description: | Specification for range based densification. tests: diff --git a/generator/config/stage/fill.yaml b/generator/config/stage/fill.yaml index d3a9ec390..2c98fac5c 100644 --- a/generator/config/stage/fill.yaml +++ b/generator/config/stage/fill.yaml @@ -29,7 +29,7 @@ arguments: - name: sortBy type: - - object # SortSpec + - sortBy optional: true description: | Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. diff --git a/generator/config/stage/geoNear.yaml b/generator/config/stage/geoNear.yaml index 699f15146..4967a0823 100644 --- a/generator/config/stage/geoNear.yaml +++ b/generator/config/stage/geoNear.yaml @@ -54,7 +54,7 @@ arguments: - name: near type: - - object # GeoPoint + - geoPoint - resolvesToObject description: | The point for which to find the closest documents. diff --git a/generator/config/stage/merge.yaml b/generator/config/stage/merge.yaml index 2e24ec74e..766092d82 100644 --- a/generator/config/stage/merge.yaml +++ b/generator/config/stage/merge.yaml @@ -12,7 +12,7 @@ arguments: name: into type: - string - - object # OutCollection + - outCollection description: | The output collection. - @@ -33,7 +33,7 @@ arguments: - name: whenMatched type: - - string # WhenMatched + - whenMatched - pipeline optional: true description: | @@ -41,7 +41,7 @@ arguments: - name: whenNotMatched type: - - string # WhenNotMatched + - whenNotMatched optional: true description: | The behavior of $merge if a result document does not match an existing document in the out collection. diff --git a/generator/config/stage/out.yaml b/generator/config/stage/out.yaml index c4cc7948d..0c3597fdf 100644 --- a/generator/config/stage/out.yaml +++ b/generator/config/stage/out.yaml @@ -10,7 +10,7 @@ arguments: - name: coll type: - string - - object # OutCollection + - outCollection description: | Target database name to write documents from $out to. tests: diff --git a/generator/config/stage/setWindowFields.yaml b/generator/config/stage/setWindowFields.yaml index fba751d03..6f86472d7 100644 --- a/generator/config/stage/setWindowFields.yaml +++ b/generator/config/stage/setWindowFields.yaml @@ -11,7 +11,7 @@ arguments: - name: sortBy type: - - object # SortSpec + - sortBy description: | Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index 2de5b3c20..11c456e69 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -49,24 +49,24 @@ final class BucketAutoStage implements StageInterface, OperatorInterface public readonly Optional|Document|Serializable|stdClass|array $output; /** - * @var Optional|Document|Serializable|array|stdClass $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. + * @var Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ - public readonly Optional|Document|Serializable|stdClass|array $granularity; + public readonly Optional|string $granularity; /** * @param ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. - * @param Optional|Document|Serializable|array|stdClass $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. + * @param Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ public function __construct( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, int $buckets, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, - Optional|Document|Serializable|stdClass|array $granularity = Optional::Undefined, + Optional|string $granularity = Optional::Undefined, ) { $this->groupBy = $groupBy; $this->buckets = $buckets; diff --git a/src/Builder/Stage/FactoryTrait.php b/src/Builder/Stage/FactoryTrait.php index 983da9e09..7bbf3bc97 100644 --- a/src/Builder/Stage/FactoryTrait.php +++ b/src/Builder/Stage/FactoryTrait.php @@ -79,14 +79,14 @@ public static function bucket( * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. - * @param Optional|Document|Serializable|array|stdClass $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. + * @param Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ public static function bucketAuto( Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy, int $buckets, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, - Optional|Document|Serializable|stdClass|array $granularity = Optional::Undefined, + Optional|string $granularity = Optional::Undefined, ): BucketAutoStage { return new BucketAutoStage($groupBy, $buckets, $output, $granularity); } diff --git a/src/Builder/Stage/FluentFactoryTrait.php b/src/Builder/Stage/FluentFactoryTrait.php index 0d6e981ea..3cfd84cff 100644 --- a/src/Builder/Stage/FluentFactoryTrait.php +++ b/src/Builder/Stage/FluentFactoryTrait.php @@ -106,14 +106,14 @@ public function bucket( * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Optional|Document|Serializable|array|stdClass $output A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. * The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. - * @param Optional|Document|Serializable|array|stdClass $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. + * @param Optional|string $granularity A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. * Available only if the all groupBy values are numeric and none of them are NaN. */ public function bucketAuto( Type|ExpressionInterface|stdClass|array|string|int|float|bool|null $groupBy, int $buckets, Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, - Optional|Document|Serializable|stdClass|array $granularity = Optional::Undefined, + Optional|string $granularity = Optional::Undefined, ): static { $this->pipeline[] = Stage::bucketAuto($groupBy, $buckets, $output, $granularity);