@base44-preview/sdk 0.8.50-pr.291.10ee07f → 0.8.51-pr.293.e71320c
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, CreateClientAnalyticsConfig, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucketUnit, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
7
|
+
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucketUnit, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityArrayOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, 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";
|
package/dist/modules/entities.js
CHANGED
|
@@ -42,8 +42,14 @@ function parseRealtimeMessage(dataStr) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
const DEFAULT_PAGE_LIMIT = 100;
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// Keys of the object form of list()/filter(). An object passed to list() with none of them is a filter query.
|
|
46
|
+
const ARRAY_OPTION_KEYS = ["sort", "limit", "skip", "fields", "filter", "query"];
|
|
47
|
+
function isPlainObject(value) {
|
|
48
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
// Code written for 0.8.49 reads a page from list()/filter() with a cursor or distinct option; keep it working.
|
|
51
|
+
function isPageRequest(value) {
|
|
52
|
+
return "cursor" in value || "distinct" in value;
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* Creates a handler for a specific entity.
|
|
@@ -73,7 +79,7 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
73
79
|
params.fields = fieldsParam(fields);
|
|
74
80
|
return axios.get(baseURL, { params });
|
|
75
81
|
};
|
|
76
|
-
// GET /{entity}/v2/list: one cursor page of records or distinct values
|
|
82
|
+
// GET /{entity}/v2/list: one cursor page of records or distinct values
|
|
77
83
|
const readPage = (options, query) => {
|
|
78
84
|
const params = {};
|
|
79
85
|
if (query)
|
|
@@ -93,15 +99,31 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
93
99
|
return axios.get(`${baseURL}/v2/list`, { params });
|
|
94
100
|
};
|
|
95
101
|
return {
|
|
96
|
-
// list(sort, limit, skip, fields) returns an array; list(options) returns one cursor page.
|
|
97
102
|
async list(...args) {
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
var _a;
|
|
104
|
+
const [first, ...rest] = args;
|
|
105
|
+
if (!isPlainObject(first))
|
|
106
|
+
return readArray(first, ...rest);
|
|
107
|
+
if (isPageRequest(first))
|
|
108
|
+
return readPage(first, first.query);
|
|
109
|
+
if (Object.keys(first).some((key) => ARRAY_OPTION_KEYS.includes(key))) {
|
|
110
|
+
return readArray(first.sort, first.limit, first.skip, first.fields, (_a = first.filter) !== null && _a !== void 0 ? _a : first.query);
|
|
111
|
+
}
|
|
112
|
+
// The object took sort's slot: list({}, 5) means limit 5; list({ email }, '-created_date', 100) follows filter()'s order.
|
|
113
|
+
return typeof rest[0] === "string"
|
|
114
|
+
? readArray(rest[0], rest[1], rest[2], rest[3], first)
|
|
115
|
+
: readArray(undefined, rest[0], rest[1], rest[2], first);
|
|
100
116
|
},
|
|
101
|
-
// filter(query, sort, limit, skip, fields) returns an array; filter(query, options) returns one cursor page.
|
|
102
117
|
async filter(query, ...args) {
|
|
103
|
-
const [
|
|
104
|
-
|
|
118
|
+
const [second, ...rest] = args;
|
|
119
|
+
if (!isPlainObject(second))
|
|
120
|
+
return readArray(second, rest[0], rest[1], rest[2], query);
|
|
121
|
+
if (isPageRequest(second))
|
|
122
|
+
return readPage(second, query);
|
|
123
|
+
return readArray(second.sort, second.limit, second.skip, second.fields, query);
|
|
124
|
+
},
|
|
125
|
+
async page(options = {}) {
|
|
126
|
+
return readPage(options, options.query);
|
|
105
127
|
},
|
|
106
128
|
// Get entity by ID
|
|
107
129
|
async get(id) {
|
|
@@ -51,13 +51,14 @@ export interface UpdateManyResult {
|
|
|
51
51
|
has_more: boolean;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Options object accepted by {@linkcode EntityHandler.
|
|
55
|
-
* {@linkcode EntityHandler.filter | filter()} to read one cursor page.
|
|
54
|
+
* Options object accepted by {@linkcode EntityHandler.page | page()} to read one cursor page of records.
|
|
56
55
|
*
|
|
57
56
|
* @typeParam T - Entity record type.
|
|
58
57
|
* @typeParam K - The fields to include in each record.
|
|
59
58
|
*/
|
|
60
59
|
export interface EntityListOptions<T, K extends keyof T = keyof T> {
|
|
60
|
+
/** Filter for the records, in the same form as {@linkcode EntityHandler.filter | filter()}'s query. Defaults to all records. */
|
|
61
|
+
query?: EntityFilterQuery<T>;
|
|
61
62
|
/** Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`. */
|
|
62
63
|
sort?: SortField<T>;
|
|
63
64
|
/** Maximum number of records per page, up to 5,000. Defaults to 100. */
|
|
@@ -73,14 +74,15 @@ export interface EntityListOptions<T, K extends keyof T = keyof T> {
|
|
|
73
74
|
fields?: K[];
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
|
-
* Options object accepted by {@linkcode EntityHandler.
|
|
77
|
-
* {@linkcode EntityHandler.filter | filter()} to read the distinct values of one field
|
|
77
|
+
* Options object accepted by {@linkcode EntityHandler.page | page()} to read the distinct values of one field
|
|
78
78
|
* instead of records.
|
|
79
79
|
*
|
|
80
80
|
* @typeParam T - Entity record type.
|
|
81
81
|
* @typeParam K - The field whose distinct values to read.
|
|
82
82
|
*/
|
|
83
83
|
export interface EntityDistinctOptions<T, K extends keyof T = keyof T> {
|
|
84
|
+
/** Filter for the records whose values are read. Defaults to all records. */
|
|
85
|
+
query?: EntityFilterQuery<T>;
|
|
84
86
|
/** Field whose distinct values to return, in ascending order. Array fields contribute each element. */
|
|
85
87
|
distinct: K;
|
|
86
88
|
/** Maximum number of values per page, up to 1,000. Defaults to 100. */
|
|
@@ -89,8 +91,26 @@ export interface EntityDistinctOptions<T, K extends keyof T = keyof T> {
|
|
|
89
91
|
cursor?: string | null;
|
|
90
92
|
}
|
|
91
93
|
/**
|
|
92
|
-
*
|
|
93
|
-
* {@linkcode EntityHandler.filter | filter()}
|
|
94
|
+
* Options object accepted by {@linkcode EntityHandler.list | list()} and
|
|
95
|
+
* {@linkcode EntityHandler.filter | filter()} in place of positional arguments. Both still return an array.
|
|
96
|
+
*
|
|
97
|
+
* @typeParam T - Entity record type.
|
|
98
|
+
* @typeParam K - The fields to include in each record.
|
|
99
|
+
*/
|
|
100
|
+
export interface EntityArrayOptions<T, K extends keyof T = keyof T> {
|
|
101
|
+
/** Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`. */
|
|
102
|
+
sort?: SortField<T>;
|
|
103
|
+
/** Maximum number of records to return. Defaults to `5000`. */
|
|
104
|
+
limit?: number;
|
|
105
|
+
/** Number of records to skip. Defaults to `0`. For loops over many records, use {@linkcode EntityHandler.page | page()}. */
|
|
106
|
+
skip?: number;
|
|
107
|
+
/** Array of field names to include in each record. Defaults to all fields. */
|
|
108
|
+
fields?: K[];
|
|
109
|
+
/** Filter for the records. Only read by `list()`; `filter()` takes its query as the first argument. */
|
|
110
|
+
filter?: EntityFilterQuery<T>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* One page of records, returned by {@linkcode EntityHandler.page | page()}.
|
|
94
114
|
*
|
|
95
115
|
* @typeParam T - Record type of the items.
|
|
96
116
|
*/
|
|
@@ -336,17 +356,19 @@ export interface EntityHandler<T = any> {
|
|
|
336
356
|
* pagination, and field selection.
|
|
337
357
|
*
|
|
338
358
|
* **Note:** The maximum limit is 5,000 items per request. To read more than
|
|
339
|
-
* one page,
|
|
340
|
-
* `
|
|
341
|
-
*
|
|
342
|
-
*
|
|
359
|
+
* one page, use {@linkcode EntityHandler.page | page()} with a cursor instead of
|
|
360
|
+
* `skip`: every page costs the same however deep you are, and records deleted
|
|
361
|
+
* between pages never shift the boundary.
|
|
362
|
+
*
|
|
363
|
+
* The arguments can also be passed as one {@linkcode EntityArrayOptions | options object}
|
|
364
|
+
* (`{ sort, limit, skip, fields, filter }`); the result is still an array.
|
|
343
365
|
*
|
|
344
366
|
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
345
367
|
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
346
368
|
* @param limit - Maximum number of results to return. Defaults to `5000`.
|
|
347
|
-
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
369
|
+
* @param skip - Number of results to skip for pagination. Defaults to `0`. For loops, use `page()`.
|
|
348
370
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
349
|
-
* @returns Promise resolving to an array of records with selected fields.
|
|
371
|
+
* @returns Promise resolving to an array of records with selected fields.
|
|
350
372
|
*
|
|
351
373
|
* @example
|
|
352
374
|
* ```typescript
|
|
@@ -375,25 +397,18 @@ export interface EntityHandler<T = any> {
|
|
|
375
397
|
*
|
|
376
398
|
* @example
|
|
377
399
|
* ```typescript
|
|
378
|
-
* //
|
|
379
|
-
*
|
|
380
|
-
* let page = await base44.entities.MyEntity.list({ sort: '-created_date', limit: 1000 });
|
|
381
|
-
* await exportRows(page.items);
|
|
382
|
-
* while (page.has_more) {
|
|
383
|
-
* page = await base44.entities.MyEntity.list({ cursor: page.next_cursor, limit: 1000 });
|
|
384
|
-
* await exportRows(page.items);
|
|
385
|
-
* }
|
|
386
|
-
* ```
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* ```typescript
|
|
390
|
-
* // Distinct values of one field, instead of records
|
|
391
|
-
* const { items: categories } = await base44.entities.Product.list({ distinct: 'category' });
|
|
400
|
+
* // The same arguments as one options object; still an array
|
|
401
|
+
* const recent = await base44.entities.MyEntity.list({ sort: '-created_date', limit: 10 });
|
|
392
402
|
* ```
|
|
393
403
|
*/
|
|
394
404
|
list<K extends keyof T = keyof T>(sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
|
|
405
|
+
list<K extends keyof T = keyof T>(options: EntityArrayOptions<T, K>): Promise<Pick<T, K>[]>;
|
|
406
|
+
/** @deprecated Use {@linkcode EntityHandler.page | page()}. */
|
|
395
407
|
list<K extends keyof T>(options: EntityDistinctOptions<T, K>): Promise<EntityPage<T[K]>>;
|
|
396
|
-
|
|
408
|
+
/** @deprecated Use {@linkcode EntityHandler.page | page()}. */
|
|
409
|
+
list<K extends keyof T = keyof T>(options: EntityListOptions<T, K> & {
|
|
410
|
+
cursor: string | null;
|
|
411
|
+
}): Promise<EntityPage<Pick<T, K>>>;
|
|
397
412
|
/**
|
|
398
413
|
* Filters records based on a query.
|
|
399
414
|
*
|
|
@@ -401,10 +416,13 @@ export interface EntityHandler<T = any> {
|
|
|
401
416
|
* sorting, pagination, and field selection.
|
|
402
417
|
*
|
|
403
418
|
* **Note:** The maximum limit is 5,000 items per request. To read more than
|
|
404
|
-
* one page,
|
|
405
|
-
* `
|
|
406
|
-
*
|
|
407
|
-
*
|
|
419
|
+
* one page, use {@linkcode EntityHandler.page | page()} with a cursor instead of
|
|
420
|
+
* `skip`: every page costs the same however deep you are, and records deleted
|
|
421
|
+
* between pages never shift the boundary.
|
|
422
|
+
*
|
|
423
|
+
* The arguments after the query can also be passed as one
|
|
424
|
+
* {@linkcode EntityArrayOptions | options object} (`{ sort, limit, skip, fields }`);
|
|
425
|
+
* the result is still an array.
|
|
408
426
|
*
|
|
409
427
|
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
410
428
|
* @param query - Query object with field-value pairs. Each key should be a field name
|
|
@@ -414,9 +432,9 @@ export interface EntityHandler<T = any> {
|
|
|
414
432
|
* provided values, or documented MongoDB query operators for advanced filtering.
|
|
415
433
|
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
416
434
|
* @param limit - Maximum number of results to return. Defaults to `5000`.
|
|
417
|
-
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
435
|
+
* @param skip - Number of results to skip for pagination. Defaults to `0`. For loops, use `page()`.
|
|
418
436
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
419
|
-
* @returns Promise resolving to an array of filtered records with selected fields.
|
|
437
|
+
* @returns Promise resolving to an array of filtered records with selected fields.
|
|
420
438
|
*
|
|
421
439
|
* @example
|
|
422
440
|
* ```typescript
|
|
@@ -496,15 +514,39 @@ export interface EntityHandler<T = any> {
|
|
|
496
514
|
*
|
|
497
515
|
* @example
|
|
498
516
|
* ```typescript
|
|
499
|
-
* //
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
517
|
+
* // Sort and limit as an options object; still an array
|
|
518
|
+
* const open = await base44.entities.Order.filter({ status: 'open' }, { sort: '-created_date', limit: 20 });
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
filter<K extends keyof T = keyof T>(query: EntityFilterQuery<T>, sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
|
|
522
|
+
filter<K extends keyof T = keyof T>(query: EntityFilterQuery<T>, options: EntityArrayOptions<T, K>): Promise<Pick<T, K>[]>;
|
|
523
|
+
/** @deprecated Use {@linkcode EntityHandler.page | page()}. */
|
|
524
|
+
filter<K extends keyof T>(query: EntityFilterQuery<T>, options: EntityDistinctOptions<T, K>): Promise<EntityPage<T[K]>>;
|
|
525
|
+
/** @deprecated Use {@linkcode EntityHandler.page | page()}. */
|
|
526
|
+
filter<K extends keyof T = keyof T>(query: EntityFilterQuery<T>, options: EntityListOptions<T, K> & {
|
|
527
|
+
cursor: string | null;
|
|
528
|
+
}): Promise<EntityPage<Pick<T, K>>>;
|
|
529
|
+
/**
|
|
530
|
+
* Reads one page of records, or of one field's distinct values, with a cursor.
|
|
531
|
+
*
|
|
532
|
+
* Use it for "load more", infinite scroll and exports. Every page costs the same
|
|
533
|
+
* however deep you are, records deleted between pages never shift the boundary,
|
|
534
|
+
* and records that share a sort value are each returned once. Pass `next_cursor`
|
|
535
|
+
* from one page as `cursor` on the next; the token carries the query, sort and
|
|
536
|
+
* fields, so a later page needs only `cursor` and `limit`. Stop when `has_more`
|
|
537
|
+
* is false. Every page holds `limit` items except the last.
|
|
538
|
+
*
|
|
539
|
+
* @typeParam K - The fields to include in each record, or the field whose values to read.
|
|
540
|
+
* @param options - `{ query, sort, limit, fields, cursor }` for records, or `{ query, distinct, limit, cursor }` for distinct values.
|
|
541
|
+
* @returns Promise resolving to an {@linkcode EntityPage | EntityPage} with `items`, `next_cursor` and `has_more`.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* // Walk all matching records
|
|
546
|
+
* let page = await base44.entities.Order.page({ query: { status: 'open' }, sort: '-created_date', limit: 1000 });
|
|
505
547
|
* await exportRows(page.items);
|
|
506
548
|
* while (page.has_more) {
|
|
507
|
-
* page = await base44.entities.Order.
|
|
549
|
+
* page = await base44.entities.Order.page({ cursor: page.next_cursor, limit: 1000 });
|
|
508
550
|
* await exportRows(page.items);
|
|
509
551
|
* }
|
|
510
552
|
* ```
|
|
@@ -512,15 +554,11 @@ export interface EntityHandler<T = any> {
|
|
|
512
554
|
* @example
|
|
513
555
|
* ```typescript
|
|
514
556
|
* // Distinct values of one field among the matching records
|
|
515
|
-
* const { items: agents } = await base44.entities.Order.
|
|
516
|
-
* { status: 'open' },
|
|
517
|
-
* { distinct: 'agent_id' }
|
|
518
|
-
* );
|
|
557
|
+
* const { items: agents } = await base44.entities.Order.page({ query: { status: 'open' }, distinct: 'agent_id' });
|
|
519
558
|
* ```
|
|
520
559
|
*/
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
filter<K extends keyof T = keyof T>(query: EntityFilterQuery<T>, options: EntityListOptions<T, K>): Promise<EntityPage<Pick<T, K>>>;
|
|
560
|
+
page<K extends keyof T>(options: EntityDistinctOptions<T, K>): Promise<EntityPage<T[K]>>;
|
|
561
|
+
page<K extends keyof T = keyof T>(options?: EntityListOptions<T, K>): Promise<EntityPage<Pick<T, K>>>;
|
|
524
562
|
/**
|
|
525
563
|
* Gets a single record by ID.
|
|
526
564
|
*
|
|
@@ -11,9 +11,11 @@ function initializeSocket(config, handlers) {
|
|
|
11
11
|
const resolvedToken = (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken();
|
|
12
12
|
const query = {
|
|
13
13
|
app_id: config.appId,
|
|
14
|
-
token: resolvedToken,
|
|
15
14
|
};
|
|
16
|
-
if (
|
|
15
|
+
if (resolvedToken) {
|
|
16
|
+
query.token = resolvedToken;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
17
19
|
query.anonymous_id = getAnalyticsSessionId();
|
|
18
20
|
}
|
|
19
21
|
const socket = io(config.serverUrl, {
|