@ptkl/sdk 1.5.1 → 1.5.3

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.3",
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,66 @@ 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 update: UpdateAggregate = [
124
+ * {
125
+ * avg_rating: { $avg: "$ratings" },
126
+ * tier: { $cond: { if: { $gte: ["$avg_rating", 4.5] }, then: "platinum", else: "standard" } }
127
+ * }
128
+ * ]
129
+ * ```
130
+ */
131
+ type UpdateAggregate = Record<string, any>[];
132
+ /**
133
+ * Aggregation-expression update (v4 only). An array of field→expression objects.
134
+ * Each element is automatically applied as a `$set` stage, so you can compute
135
+ * new field values from the existing document using MongoDB aggregation
136
+ * expressions (`$cond`, `$avg`, `$map`, `$ifNull`, etc.).
137
+ *
138
+ * The write always runs in a transaction and is rolled back if the resulting
139
+ * document fails IDL validation. Cannot be combined with regular update
140
+ * operators (`$inc`, `$push`, etc.) in the same request.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * await product.update(uuid, {
145
+ * $aggregate: [
146
+ * {
147
+ * avg_rating: { $avg: "$ratings" },
148
+ * tier: {
149
+ * $cond: {
150
+ * if: { $gte: ["$avg_rating", 4.5] },
151
+ * then: "platinum",
152
+ * else: "standard",
153
+ * },
154
+ * },
155
+ * },
156
+ * ],
157
+ * })
158
+ * ```
159
+ */
118
160
  /**
119
161
  * Model data payload that supports inline update operators.
120
162
  * Regular fields are applied via `$set`, operator keys are applied with their
121
163
  * respective MongoDB semantics.
164
+ *
165
+ * Pass `$aggregate` (v4 only) to use an aggregation-expression update instead
166
+ * of plain operators. `$aggregate` and regular operators are mutually exclusive.
122
167
  */
123
- type ModelUpdateData = Record<string, any> & UpdateOperators;
168
+ type ModelUpdateData = Record<string, any> & UpdateOperators & {
169
+ /** Aggregation-expression update (v4 only). Mutually exclusive with operator keys. */
170
+ $aggregate?: UpdateAggregate;
171
+ };
124
172
  type ComponentOptions = {
125
173
  version?: string;
126
174
  };
@@ -366,4 +414,4 @@ type SetupData = {
366
414
  integrator?: string;
367
415
  };
368
416
  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, };
417
+ export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, UpdateOperators, UpdateAggregate, 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.3",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",