@base44-preview/sdk 0.8.26-pr.167.9a82260 → 0.8.26-pr.169.4ce3986

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/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
4
4
  export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
5
5
  export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
6
6
  export * from "./types.js";
7
- export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
7
+ export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
8
8
  export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
9
9
  export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
10
10
  export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
@@ -41,34 +41,6 @@ function parseRealtimeMessage(dataStr) {
41
41
  return null;
42
42
  }
43
43
  }
44
- // In-flight HTTP refetches for oversize realtime events. Lets multiple
45
- // subscribers in the same browser (e.g. several React components subscribed
46
- // to the same entity) share one HTTP call when they all receive the same
47
- // oversize event. Keyed by `${entityName}:${id}:${timestamp}` so distinct
48
- // updates are not collapsed.
49
- const inflightRefetches = new Map();
50
- /**
51
- * Refetches a record over HTTP after the server signaled it had to slim the
52
- * realtime broadcast (`_oversize: true`). Reuses an in-flight promise if
53
- * one exists for the same (entityName, id, timestamp) so concurrent
54
- * subscribers in the same browser fan out to a single HTTP call.
55
- * @internal
56
- */
57
- function refetchTruncated(axios, baseURL, entityName, id, timestamp) {
58
- const key = `${entityName}:${id}:${timestamp}`;
59
- let promise = inflightRefetches.get(key);
60
- if (!promise) {
61
- promise = axios.get(`${baseURL}/${id}`);
62
- inflightRefetches.set(key, promise);
63
- // Clear the cache entry after the promise settles plus a short grace
64
- // window so late subscribers can still piggy-back on the result. Use
65
- // .then(success, failure) instead of .finally to avoid creating an
66
- // unhandled rejection tail when the underlying axios call rejects.
67
- const cleanup = () => setTimeout(() => inflightRefetches.delete(key), 5000);
68
- promise.then(cleanup, cleanup);
69
- }
70
- return promise;
71
- }
72
44
  /**
73
45
  * Creates a handler for a specific entity.
74
46
  *
@@ -158,26 +130,11 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
158
130
  // Get the socket and subscribe to the room
159
131
  const socket = getSocket();
160
132
  const unsubscribe = socket.subscribeToRoom(room, {
161
- update_model: async (msg) => {
162
- var _a;
133
+ update_model: (msg) => {
163
134
  const event = parseRealtimeMessage(msg.data);
164
135
  if (!event) {
165
136
  return;
166
137
  }
167
- // Server signals oversize broadcasts with `_oversize: true` on
168
- // `data`. The wire payload is bounded for transport; we transparently
169
- // refetch the full record over HTTP so callers always see complete
170
- // data. Skip on delete events — the record no longer exists.
171
- if (event.type !== "delete" && ((_a = event.data) === null || _a === void 0 ? void 0 : _a._oversize)) {
172
- try {
173
- event.data = await refetchTruncated(axios, baseURL, entityName, event.id, event.timestamp);
174
- }
175
- catch (error) {
176
- console.warn("[Base44 SDK] Failed to refetch oversize entity, falling through with stub payload:", error);
177
- // event.data stays as the `{id, _oversize: true}` stub; user
178
- // code receives partial data — same UX as today's drop-and-stale.
179
- }
180
- }
181
138
  try {
182
139
  callback(event);
183
140
  }
@@ -84,6 +84,61 @@ export interface ImportResult<T = any> {
84
84
  * ```
85
85
  */
86
86
  export type SortField<T> = (keyof T & string) | `+${keyof T & string}` | `-${keyof T & string}`;
87
+ /**
88
+ * Value accepted when filtering an entity field.
89
+ *
90
+ * Supports exact matches, `null`, array shorthand for matching any of the
91
+ * provided values, and documented MongoDB-style query operators.
92
+ *
93
+ * @typeParam T - Field value type.
94
+ */
95
+ export type EntityFilterValue<T> = EntityFilterComparable<T> | EntityFilterComparable<T>[] | EntityFilterOperators<T>;
96
+ /**
97
+ * MongoDB-style query operators accepted for a single entity field.
98
+ *
99
+ * @typeParam T - Field value type.
100
+ */
101
+ export type EntityFilterOperators<T> = EntityFilterCommonOperators<T> & {
102
+ /** Negates another field-level filter expression. */
103
+ $not?: EntityFilterCommonOperators<T>;
104
+ };
105
+ type EntityFilterComparable<T> = Exclude<T, undefined> | null;
106
+ type EntityFilterCommonOperators<T> = {
107
+ $eq?: EntityFilterComparable<T>;
108
+ $ne?: EntityFilterComparable<T>;
109
+ $gt?: EntityFilterComparable<T>;
110
+ $gte?: EntityFilterComparable<T>;
111
+ $lt?: EntityFilterComparable<T>;
112
+ $lte?: EntityFilterComparable<T>;
113
+ $in?: EntityFilterComparable<T>[];
114
+ $nin?: EntityFilterComparable<T>[];
115
+ $exists?: boolean;
116
+ } & EntityFilterStringOperators<T> & EntityFilterArrayOperators<T>;
117
+ type EntityFilterStringOperators<T> = Extract<Exclude<T, undefined | null>, string> extends never ? {} : {
118
+ $regex?: string;
119
+ };
120
+ type EntityFilterArrayElement<T> = T extends readonly (infer U)[] ? U : never;
121
+ type EntityFilterArrayOperators<T> = [
122
+ EntityFilterArrayElement<Exclude<T, undefined | null>>
123
+ ] extends [never] ? {} : {
124
+ $all?: EntityFilterArrayElement<Exclude<T, undefined | null>>[];
125
+ $size?: number;
126
+ };
127
+ /**
128
+ * Query object accepted by entity filtering methods.
129
+ *
130
+ * Field keys are typed from the entity schema. `$and`, `$or`, and `$nor`
131
+ * combine nested filter queries at the root level.
132
+ *
133
+ * @typeParam T - Entity record type.
134
+ */
135
+ export type EntityFilterQuery<T> = {
136
+ [K in keyof T]?: EntityFilterValue<T[K]>;
137
+ } & {
138
+ $and?: EntityFilterQuery<T>[];
139
+ $or?: EntityFilterQuery<T>[];
140
+ $nor?: EntityFilterQuery<T>[];
141
+ };
87
142
  /**
88
143
  * Fields added by the server to every entity record, such as `id`, `created_date`, `updated_date`, and `created_by`.
89
144
  */
@@ -189,7 +244,9 @@ export interface EntityHandler<T = any> {
189
244
  * @typeParam K - The fields to include in the response. Defaults to all fields.
190
245
  * @param query - Query object with field-value pairs. Each key should be a field name
191
246
  * from your entity schema, and each value is the criteria to match. Records matching all
192
- * specified criteria are returned. Field names are case-sensitive.
247
+ * specified criteria are returned. Field names are case-sensitive. Use field-value pairs
248
+ * for exact matches, `null` for null values, arrays as shorthand for matching any of the
249
+ * provided values, or documented MongoDB query operators for advanced filtering.
193
250
  * @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
194
251
  * @param limit - Maximum number of results to return. Defaults to `50`.
195
252
  * @param skip - Number of results to skip for pagination. Defaults to `0`.
@@ -215,6 +272,42 @@ export interface EntityHandler<T = any> {
215
272
  *
216
273
  * @example
217
274
  * ```typescript
275
+ * // Filter by any matching value
276
+ * const records = await base44.entities.MyEntity.filter({
277
+ * external_id: ['item-1', 'item-2']
278
+ * });
279
+ * ```
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * // Filter with query operators
284
+ * const popularRecords = await base44.entities.MyEntity.filter({
285
+ * count: { $gte: 100 },
286
+ * external_id: { $in: ['item-1', 'item-2'] }
287
+ * });
288
+ * ```
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * // Filter with logical operators
293
+ * const records = await base44.entities.MyEntity.filter({
294
+ * $or: [
295
+ * { name: 'Example item' },
296
+ * { slug: 'example-item' }
297
+ * ]
298
+ * });
299
+ * ```
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * // Filter null values
304
+ * const recordsWithoutDescription = await base44.entities.MyEntity.filter({
305
+ * description: null
306
+ * });
307
+ * ```
308
+ *
309
+ * @example
310
+ * ```typescript
218
311
  * // Filter with sorting and pagination
219
312
  * const results = await base44.entities.MyEntity.filter(
220
313
  * { status: 'active' },
@@ -236,7 +329,7 @@ export interface EntityHandler<T = any> {
236
329
  * );
237
330
  * ```
238
331
  */
239
- filter<K extends keyof T = keyof T>(query: Partial<T>, sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
332
+ filter<K extends keyof T = keyof T>(query: EntityFilterQuery<T>, sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
240
333
  /**
241
334
  * Gets a single record by ID.
242
335
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.26-pr.167.9a82260",
3
+ "version": "0.8.26-pr.169.4ce3986",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "lint": "eslint src",
14
- "test": "vitest run",
14
+ "test": "npm run test:types && vitest run",
15
+ "test:types": "tsc --noEmit -p tsconfig.type-tests.json",
15
16
  "test:unit": "vitest run tests/unit",
16
17
  "test:e2e": "vitest run tests/e2e",
17
18
  "test:watch": "vitest",