@superblocksteam/sdk-api 2.0.106-next.0 → 2.0.106-next.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk-api",
3
- "version": "2.0.106-next.0",
3
+ "version": "2.0.106-next.2",
4
4
  "description": "Superblocks SDK for TypeScript-based API definitions",
5
5
  "license": "Superblocks Community Software License",
6
6
  "files": [
@@ -79,16 +79,21 @@ const UserSchema = z
79
79
  name: z.string(),
80
80
  email: z.string(),
81
81
  })
82
- .nullable();
82
+ .nullable()
83
+ .optional();
83
84
 
84
85
  const user = await ctx.integrations.mongodb.run(
85
86
  "users",
86
87
  "findOne",
87
88
  UserSchema,
88
89
  {
89
- query: { _id: userId },
90
+ query: { _id: { $oid: userId } },
90
91
  },
91
92
  );
93
+
94
+ // findOne returns undefined (not null) when no document matches,
95
+ // so use .nullable().optional() and coalesce if needed:
96
+ const result = user ?? null;
92
97
  ```
93
98
 
94
99
  ### Insert Document
@@ -116,8 +121,8 @@ const result = await ctx.integrations.mongodb.run(
116
121
 
117
122
  ```typescript
118
123
  const UpdateResultSchema = z.object({
119
- matchedCount: z.number(),
120
- modifiedCount: z.number(),
124
+ matchedCount: z.coerce.number(),
125
+ modifiedCount: z.coerce.number(),
121
126
  });
122
127
 
123
128
  const result = await ctx.integrations.mongodb.run(
@@ -125,7 +130,7 @@ const result = await ctx.integrations.mongodb.run(
125
130
  "updateOne",
126
131
  UpdateResultSchema,
127
132
  {
128
- filter: { _id: userId },
133
+ filter: { _id: { $oid: userId } },
129
134
  update: {
130
135
  $set: { status: "active", updatedAt: new Date().toISOString() },
131
136
  },
@@ -137,7 +142,7 @@ const result = await ctx.integrations.mongodb.run(
137
142
 
138
143
  ```typescript
139
144
  const DeleteResultSchema = z.object({
140
- deletedCount: z.number(),
145
+ deletedCount: z.coerce.number(),
141
146
  });
142
147
 
143
148
  const result = await ctx.integrations.mongodb.run(
@@ -145,7 +150,7 @@ const result = await ctx.integrations.mongodb.run(
145
150
  "deleteOne",
146
151
  DeleteResultSchema,
147
152
  {
148
- filter: { _id: userId },
153
+ filter: { _id: { $oid: userId } },
149
154
  },
150
155
  );
151
156
  ```
@@ -156,8 +161,8 @@ const result = await ctx.integrations.mongodb.run(
156
161
  const AggregateResultSchema = z.array(
157
162
  z.object({
158
163
  _id: z.string(),
159
- count: z.number(),
160
- totalAmount: z.number(),
164
+ count: z.coerce.number(),
165
+ totalAmount: z.coerce.number(),
161
166
  }),
162
167
  );
163
168
 
@@ -183,9 +188,14 @@ const result = await ctx.integrations.mongodb.run(
183
188
  ### Count Documents
184
189
 
185
190
  ```typescript
186
- const count = await ctx.integrations.mongodb.run("users", "count", z.number(), {
187
- query: { status: "active" },
188
- });
191
+ const count = await ctx.integrations.mongodb.run(
192
+ "users",
193
+ "count",
194
+ z.coerce.number(),
195
+ {
196
+ query: { status: "active" },
197
+ },
198
+ );
189
199
  ```
190
200
 
191
201
  ### Find with Projection and Sort
@@ -245,6 +255,49 @@ try {
245
255
  }
246
256
  ```
247
257
 
258
+ ## Gotchas
259
+
260
+ ### Numeric fields are returned as strings
261
+
262
+ MongoDB numeric values (e.g. `int32`, `int64`, `double`) are returned as strings by the integration. Using `z.number()` in your schema will fail with `"Expected number, received string"`. Use `z.coerce.number()` instead to automatically convert string values to numbers:
263
+
264
+ ```typescript
265
+ // ❌ Will fail — MongoDB returns numbers as strings
266
+ const Schema = z.object({ rating: z.number() });
267
+
268
+ // ✅ Correct — coerces string values to numbers
269
+ const Schema = z.object({ rating: z.coerce.number() });
270
+ ```
271
+
272
+ ### ObjectId fields require `$oid` syntax
273
+
274
+ When querying by `_id` or any ObjectId field, passing a plain string does not match. You must wrap the value using MongoDB Extended JSON `$oid` syntax:
275
+
276
+ ```typescript
277
+ // ❌ Will not match — returns null/undefined
278
+ const bad = { query: { _id: userId } };
279
+
280
+ // ✅ Correct — uses Extended JSON $oid wrapper
281
+ const good = { query: { _id: { $oid: userId } } };
282
+ ```
283
+
284
+ This applies to `findOne`, `updateOne`, `deleteOne`, and any operation filtering by ObjectId fields.
285
+
286
+ ### `findOne` returns `undefined` when no document matches
287
+
288
+ When no document is found, `findOne` returns `undefined` rather than `null`. If your schema uses only `.nullable()`, Zod will reject `undefined` with `"Expected object, received undefined"`. Use `.nullable().optional()` to handle both cases:
289
+
290
+ ```typescript
291
+ // ❌ Will fail when no document matches
292
+ const Schema = z.object({ name: z.string() }).nullable();
293
+
294
+ // ✅ Correct — handles both null and undefined
295
+ const Schema = z.object({ name: z.string() }).nullable().optional();
296
+
297
+ // Coalesce to null if needed
298
+ const result = (await ctx.integrations.mongodb.run(...)) ?? null;
299
+ ```
300
+
248
301
  ## API Reference
249
302
 
250
303
  - [MongoDB Manual](https://www.mongodb.com/docs/manual/)