@xata.io/client 0.23.3 → 0.23.4
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/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +50 -10
- package/dist/index.mjs +6 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1293,7 +1293,7 @@ type FilterColumnIncludes = {
|
|
1293
1293
|
$includesNone?: FilterPredicate;
|
1294
1294
|
};
|
1295
1295
|
type FilterColumn = FilterColumnIncludes | FilterPredicate | FilterList;
|
1296
|
-
type SortOrder = 'asc' | 'desc';
|
1296
|
+
type SortOrder = 'asc' | 'desc' | 'random';
|
1297
1297
|
type SortExpression = string[] | {
|
1298
1298
|
[key: string]: SortOrder;
|
1299
1299
|
} | {
|
@@ -4611,6 +4611,37 @@ type QueryTableVariables = {
|
|
4611
4611
|
* }
|
4612
4612
|
* ```
|
4613
4613
|
*
|
4614
|
+
* It is also possible to sort results randomly:
|
4615
|
+
*
|
4616
|
+
* ```json
|
4617
|
+
* POST /db/demo:main/tables/table/query
|
4618
|
+
* {
|
4619
|
+
* "sort": {
|
4620
|
+
* "*": "random"
|
4621
|
+
* }
|
4622
|
+
* }
|
4623
|
+
* ```
|
4624
|
+
*
|
4625
|
+
* Note that a random sort does not apply to a specific column, hence the special column name `"*"`.
|
4626
|
+
*
|
4627
|
+
* A random sort can be combined with an ascending or descending sort on a specific column:
|
4628
|
+
*
|
4629
|
+
* ```json
|
4630
|
+
* POST /db/demo:main/tables/table/query
|
4631
|
+
* {
|
4632
|
+
* "sort": [
|
4633
|
+
* {
|
4634
|
+
* "name": "desc"
|
4635
|
+
* },
|
4636
|
+
* {
|
4637
|
+
* "*": "random"
|
4638
|
+
* }
|
4639
|
+
* ]
|
4640
|
+
* }
|
4641
|
+
* ```
|
4642
|
+
*
|
4643
|
+
* This will sort on the `name` column, breaking ties randomly.
|
4644
|
+
*
|
4614
4645
|
* ### Pagination
|
4615
4646
|
*
|
4616
4647
|
* We offer cursor pagination and offset pagination. For queries that are expected to return more than 1000 records,
|
@@ -6794,11 +6825,18 @@ type AskResult = {
|
|
6794
6825
|
};
|
6795
6826
|
|
6796
6827
|
type SortDirection = 'asc' | 'desc';
|
6797
|
-
type
|
6828
|
+
type RandomFilter = {
|
6829
|
+
'*': 'random';
|
6830
|
+
};
|
6831
|
+
type RandomFilterExtended = {
|
6832
|
+
column: '*';
|
6833
|
+
direction: 'random';
|
6834
|
+
};
|
6835
|
+
type SortFilterExtended<T extends XataRecord, Columns extends string = ColumnsByValue<T, any>> = RandomFilterExtended | {
|
6798
6836
|
column: Columns;
|
6799
6837
|
direction?: SortDirection;
|
6800
6838
|
};
|
6801
|
-
type SortFilter<T extends XataRecord, Columns extends string = ColumnsByValue<T, any>> = Columns | SortFilterExtended<T, Columns> | SortFilterBase<T, Columns
|
6839
|
+
type SortFilter<T extends XataRecord, Columns extends string = ColumnsByValue<T, any>> = Columns | SortFilterExtended<T, Columns> | SortFilterBase<T, Columns> | RandomFilter;
|
6802
6840
|
type SortFilterBase<T extends XataRecord, Columns extends string = ColumnsByValue<T, any>> = Values<{
|
6803
6841
|
[Key in Columns]: {
|
6804
6842
|
[K in Key]: SortDirection;
|
@@ -6930,7 +6968,9 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
6930
6968
|
* @param direction The direction. Either ascending or descending.
|
6931
6969
|
* @returns A new Query object.
|
6932
6970
|
*/
|
6933
|
-
sort<F extends ColumnsByValue<Record, any>>(column: F, direction
|
6971
|
+
sort<F extends ColumnsByValue<Record, any>>(column: F, direction: SortDirection): Query<Record, Result>;
|
6972
|
+
sort(column: '*', direction: 'random'): Query<Record, Result>;
|
6973
|
+
sort<F extends ColumnsByValue<Record, any>>(column: F): Query<Record, Result>;
|
6934
6974
|
/**
|
6935
6975
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
6936
6976
|
* @param columns Array of column names to be returned by the query.
|
@@ -6956,7 +6996,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
6956
6996
|
* @param options Pagination options
|
6957
6997
|
* @returns A page of results
|
6958
6998
|
*/
|
6959
|
-
getPaginated<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<Page<Record, SelectedPick<Record, typeof options['columns']>>>;
|
6999
|
+
getPaginated<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<Page<Record, SelectedPick<Record, (typeof options)['columns']>>>;
|
6960
7000
|
/**
|
6961
7001
|
* Get results in an iterator
|
6962
7002
|
*
|
@@ -6987,7 +7027,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
6987
7027
|
*/
|
6988
7028
|
getIterator<Options extends RequiredBy<OmitBy<QueryOptions<Record>, 'pagination'>, 'columns'> & {
|
6989
7029
|
batchSize?: number;
|
6990
|
-
}>(options: Options): AsyncGenerator<SelectedPick<Record, typeof options['columns']>[]>;
|
7030
|
+
}>(options: Options): AsyncGenerator<SelectedPick<Record, (typeof options)['columns']>[]>;
|
6991
7031
|
/**
|
6992
7032
|
* Performs the query in the database and returns a set of results.
|
6993
7033
|
* @returns An array of records from the database.
|
@@ -6998,7 +7038,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
6998
7038
|
* @param options Additional options to be used when performing the query.
|
6999
7039
|
* @returns An array of records from the database.
|
7000
7040
|
*/
|
7001
|
-
getMany<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<RecordArray<SelectedPick<Record, typeof options['columns']>>>;
|
7041
|
+
getMany<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<RecordArray<SelectedPick<Record, (typeof options)['columns']>>>;
|
7002
7042
|
/**
|
7003
7043
|
* Performs the query in the database and returns a set of results.
|
7004
7044
|
* @param options Additional options to be used when performing the query.
|
@@ -7019,7 +7059,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
7019
7059
|
*/
|
7020
7060
|
getAll<Options extends RequiredBy<OmitBy<QueryOptions<Record>, 'pagination'>, 'columns'> & {
|
7021
7061
|
batchSize?: number;
|
7022
|
-
}>(options: Options): Promise<SelectedPick<Record, typeof options['columns']>[]>;
|
7062
|
+
}>(options: Options): Promise<SelectedPick<Record, (typeof options)['columns']>[]>;
|
7023
7063
|
/**
|
7024
7064
|
* Performs the query in the database and returns all the results.
|
7025
7065
|
* Warning: If there are a large number of results, this method can have performance implications.
|
@@ -7039,7 +7079,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
7039
7079
|
* @param options Additional options to be used when performing the query.
|
7040
7080
|
* @returns The first record that matches the query, or null if no record matched the query.
|
7041
7081
|
*/
|
7042
|
-
getFirst<Options extends RequiredBy<OmitBy<QueryOptions<Record>, 'pagination'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']> | null>;
|
7082
|
+
getFirst<Options extends RequiredBy<OmitBy<QueryOptions<Record>, 'pagination'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, (typeof options)['columns']> | null>;
|
7043
7083
|
/**
|
7044
7084
|
* Performs the query in the database and returns the first result.
|
7045
7085
|
* @param options Additional options to be used when performing the query.
|
@@ -7058,7 +7098,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
7058
7098
|
* @returns The first record that matches the query, or null if no record matched the query.
|
7059
7099
|
* @throws if there are no results.
|
7060
7100
|
*/
|
7061
|
-
getFirstOrThrow<Options extends RequiredBy<OmitBy<QueryOptions<Record>, 'pagination'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']>>;
|
7101
|
+
getFirstOrThrow<Options extends RequiredBy<OmitBy<QueryOptions<Record>, 'pagination'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, (typeof options)['columns']>>;
|
7062
7102
|
/**
|
7063
7103
|
* Performs the query in the database and returns the first result.
|
7064
7104
|
* @param options Additional options to be used when performing the query.
|
package/dist/index.mjs
CHANGED
@@ -490,7 +490,7 @@ function defaultOnOpen(response) {
|
|
490
490
|
}
|
491
491
|
}
|
492
492
|
|
493
|
-
const VERSION = "0.23.
|
493
|
+
const VERSION = "0.23.4";
|
494
494
|
|
495
495
|
class ErrorWithCause extends Error {
|
496
496
|
constructor(message, options) {
|
@@ -2609,7 +2609,11 @@ function isSortFilterString(value) {
|
|
2609
2609
|
return isString(value);
|
2610
2610
|
}
|
2611
2611
|
function isSortFilterBase(filter) {
|
2612
|
-
return isObject(filter) && Object.
|
2612
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2613
|
+
if (key === "*")
|
2614
|
+
return value === "random";
|
2615
|
+
return value === "asc" || value === "desc";
|
2616
|
+
});
|
2613
2617
|
}
|
2614
2618
|
function isSortFilterObject(filter) {
|
2615
2619
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|