@ptkl/sdk 1.5.1 → 1.5.2

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",
@@ -89,7 +89,6 @@ type ModifyOptions = {
89
89
  * - `$pull` — Remove from an array by condition
90
90
  * - `$addToSet` — Add to array only if not present
91
91
  * - `$pop` — Remove first (-1) or last (1) element from array
92
- * - `$unset` — Remove a field from the document
93
92
  * - `$min` — Update only if new value is less than current
94
93
  * - `$max` — Update only if new value is greater than current
95
94
  * - `$mul` — Multiply a numeric field
@@ -110,17 +109,65 @@ type UpdateOperators = {
110
109
  $pull?: Record<string, any>;
111
110
  $addToSet?: Record<string, any>;
112
111
  $pop?: Record<string, 1 | -1>;
113
- $unset?: Record<string, "">;
114
112
  $min?: Record<string, any>;
115
113
  $max?: Record<string, any>;
116
114
  $mul?: Record<string, number>;
117
115
  };
116
+ /**
117
+ * A single element in an `$aggregate` update array. Each element is a plain
118
+ * object mapping field names to MongoDB aggregation expressions. You do **not**
119
+ * need to wrap the object in a `$set` — the API does that automatically.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * const elem: UpdateAggregateElement = {
124
+ * avg_rating: { $avg: "$ratings" },
125
+ * tier: { $cond: { if: { $gte: ["$avg_rating", 4.5] }, then: "platinum", else: "standard" } }
126
+ * }
127
+ * ```
128
+ */
129
+ type UpdateAggregateElement = Record<string, any>;
130
+ /**
131
+ * Aggregation-expression update (v4 only). An array of field→expression objects.
132
+ * Each element is automatically applied as a `$set` stage, so you can compute
133
+ * new field values from the existing document using MongoDB aggregation
134
+ * expressions (`$cond`, `$avg`, `$map`, `$ifNull`, etc.).
135
+ *
136
+ * The write always runs in a transaction and is rolled back if the resulting
137
+ * document fails IDL validation. Cannot be combined with regular update
138
+ * operators (`$inc`, `$push`, etc.) in the same request.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * await product.update(uuid, {
143
+ * $aggregate: [
144
+ * {
145
+ * avg_rating: { $avg: "$ratings" },
146
+ * tier: {
147
+ * $cond: {
148
+ * if: { $gte: ["$avg_rating", 4.5] },
149
+ * then: "platinum",
150
+ * else: "standard",
151
+ * },
152
+ * },
153
+ * },
154
+ * ],
155
+ * })
156
+ * ```
157
+ */
158
+ type UpdateAggregatePipeline = UpdateAggregateElement[];
118
159
  /**
119
160
  * Model data payload that supports inline update operators.
120
161
  * Regular fields are applied via `$set`, operator keys are applied with their
121
162
  * respective MongoDB semantics.
163
+ *
164
+ * Pass `$aggregate` (v4 only) to use an aggregation-expression update instead
165
+ * of plain operators. `$aggregate` and regular operators are mutually exclusive.
122
166
  */
123
- type ModelUpdateData = Record<string, any> & UpdateOperators;
167
+ type ModelUpdateData = Record<string, any> & UpdateOperators & {
168
+ /** Aggregation-expression update (v4 only). Mutually exclusive with operator keys. */
169
+ $aggregate?: UpdateAggregatePipeline;
170
+ };
124
171
  type ComponentOptions = {
125
172
  version?: string;
126
173
  };
@@ -366,4 +413,4 @@ type SetupData = {
366
413
  integrator?: string;
367
414
  };
368
415
  type ComponentCreateResponse = ComponentListItem;
369
- export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, UpdateOperators, ModelUpdateData, ComponentOptions, ComponentListResponse, ComponentListItem, ComponentLabel, ComponentWorkspace, StreamCallback, StreamHandler, AggregateChainable, UpdateManyOptions, CreateManyOptions, Settings, SettingsField, FieldRoles, FieldConstraints, Context, Preset, PresetContext, Filters, Function, Extension, Policy, FieldAccessConfig, TemplatesDist, SetupData, ComponentCreateResponse, };
416
+ export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, UpdateOperators, UpdateAggregatePipelineStage, UpdateAggregatePipeline, ModelUpdateData, ComponentOptions, ComponentListResponse, ComponentListItem, ComponentLabel, ComponentWorkspace, StreamCallback, StreamHandler, AggregateChainable, UpdateManyOptions, CreateManyOptions, Settings, SettingsField, FieldRoles, FieldConstraints, Context, Preset, PresetContext, Filters, Function, Extension, Policy, FieldAccessConfig, TemplatesDist, SetupData, ComponentCreateResponse, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",