@xata.io/client 0.0.0-alpha.vf6d8daa → 0.0.0-alpha.vf6f2567
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.cjs +30 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.mjs +30 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -20,15 +20,25 @@ declare type ErrorWrapper<TError> = TError | {
|
|
20
20
|
};
|
21
21
|
|
22
22
|
interface CacheImpl {
|
23
|
+
cacheRecords: boolean;
|
24
|
+
defaultQueryTTL: number;
|
23
25
|
getAll(): Promise<Record<string, unknown>>;
|
24
26
|
get: <T>(key: string) => Promise<T | null>;
|
25
27
|
set: <T>(key: string, value: T) => Promise<void>;
|
26
28
|
delete: (key: string) => Promise<void>;
|
27
29
|
clear: () => Promise<void>;
|
28
30
|
}
|
31
|
+
interface SimpleCacheOptions {
|
32
|
+
max?: number;
|
33
|
+
cacheRecords?: boolean;
|
34
|
+
defaultQueryTTL?: number;
|
35
|
+
}
|
29
36
|
declare class SimpleCache implements CacheImpl {
|
30
37
|
#private;
|
31
|
-
|
38
|
+
capacity: number;
|
39
|
+
cacheRecords: boolean;
|
40
|
+
defaultQueryTTL: number;
|
41
|
+
constructor(options?: SimpleCacheOptions);
|
32
42
|
getAll(): Promise<Record<string, unknown>>;
|
33
43
|
get<T>(key: string): Promise<T | null>;
|
34
44
|
set<T>(key: string, value: T): Promise<void>;
|
@@ -1284,8 +1294,9 @@ declare type UpdateTableVariables = {
|
|
1284
1294
|
*
|
1285
1295
|
* In the example below, we rename a table from “users” to “people”:
|
1286
1296
|
*
|
1287
|
-
* ```
|
1288
|
-
* PATCH /db/test:main/tables/users
|
1297
|
+
* ```json
|
1298
|
+
* // PATCH /db/test:main/tables/users
|
1299
|
+
*
|
1289
1300
|
* {
|
1290
1301
|
* "name": "people"
|
1291
1302
|
* }
|
@@ -1693,7 +1704,7 @@ declare type QueryTableVariables = {
|
|
1693
1704
|
* {
|
1694
1705
|
* "columns": [...],
|
1695
1706
|
* "filter": {
|
1696
|
-
* "$all": [...]
|
1707
|
+
* "$all": [...],
|
1697
1708
|
* "$any": [...]
|
1698
1709
|
* ...
|
1699
1710
|
* },
|
@@ -1827,7 +1838,7 @@ declare type QueryTableVariables = {
|
|
1827
1838
|
* {
|
1828
1839
|
* "name": "Kilian",
|
1829
1840
|
* "address": {
|
1830
|
-
* "street": "New street"
|
1841
|
+
* "street": "New street"
|
1831
1842
|
* }
|
1832
1843
|
* }
|
1833
1844
|
* ```
|
@@ -1836,10 +1847,7 @@ declare type QueryTableVariables = {
|
|
1836
1847
|
*
|
1837
1848
|
* ```json
|
1838
1849
|
* {
|
1839
|
-
* "columns": [
|
1840
|
-
* "*",
|
1841
|
-
* "team.name"
|
1842
|
-
* ]
|
1850
|
+
* "columns": ["*", "team.name"]
|
1843
1851
|
* }
|
1844
1852
|
* ```
|
1845
1853
|
*
|
@@ -1857,7 +1865,7 @@ declare type QueryTableVariables = {
|
|
1857
1865
|
* "team": {
|
1858
1866
|
* "id": "XX",
|
1859
1867
|
* "xata": {
|
1860
|
-
* "version": 0
|
1868
|
+
* "version": 0
|
1861
1869
|
* },
|
1862
1870
|
* "name": "first team"
|
1863
1871
|
* }
|
@@ -1868,10 +1876,7 @@ declare type QueryTableVariables = {
|
|
1868
1876
|
*
|
1869
1877
|
* ```json
|
1870
1878
|
* {
|
1871
|
-
* "columns": [
|
1872
|
-
* "*",
|
1873
|
-
* "team.*"
|
1874
|
-
* ]
|
1879
|
+
* "columns": ["*", "team.*"]
|
1875
1880
|
* }
|
1876
1881
|
* ```
|
1877
1882
|
*
|
@@ -1889,7 +1894,7 @@ declare type QueryTableVariables = {
|
|
1889
1894
|
* "team": {
|
1890
1895
|
* "id": "XX",
|
1891
1896
|
* "xata": {
|
1892
|
-
* "version": 0
|
1897
|
+
* "version": 0
|
1893
1898
|
* },
|
1894
1899
|
* "name": "first team",
|
1895
1900
|
* "code": "A1"
|
@@ -1938,7 +1943,7 @@ declare type QueryTableVariables = {
|
|
1938
1943
|
* ```json
|
1939
1944
|
* {
|
1940
1945
|
* "filter": {
|
1941
|
-
*
|
1946
|
+
* "name": "r2"
|
1942
1947
|
* }
|
1943
1948
|
* }
|
1944
1949
|
* ```
|
@@ -1960,7 +1965,7 @@ declare type QueryTableVariables = {
|
|
1960
1965
|
* ```json
|
1961
1966
|
* {
|
1962
1967
|
* "filter": {
|
1963
|
-
*
|
1968
|
+
* "settings.plan": "free"
|
1964
1969
|
* }
|
1965
1970
|
* }
|
1966
1971
|
* ```
|
@@ -1970,8 +1975,8 @@ declare type QueryTableVariables = {
|
|
1970
1975
|
* "filter": {
|
1971
1976
|
* "settings": {
|
1972
1977
|
* "plan": "free"
|
1973
|
-
* }
|
1974
|
-
* }
|
1978
|
+
* }
|
1979
|
+
* }
|
1975
1980
|
* }
|
1976
1981
|
* ```
|
1977
1982
|
*
|
@@ -1980,8 +1985,8 @@ declare type QueryTableVariables = {
|
|
1980
1985
|
* ```json
|
1981
1986
|
* {
|
1982
1987
|
* "filter": {
|
1983
|
-
* "settings.plan": {"$any": ["free", "paid"]}
|
1984
|
-
* }
|
1988
|
+
* "settings.plan": { "$any": ["free", "paid"] }
|
1989
|
+
* }
|
1985
1990
|
* }
|
1986
1991
|
* ```
|
1987
1992
|
*
|
@@ -1990,9 +1995,9 @@ declare type QueryTableVariables = {
|
|
1990
1995
|
* ```json
|
1991
1996
|
* {
|
1992
1997
|
* "filter": {
|
1993
|
-
*
|
1994
|
-
*
|
1995
|
-
* }
|
1998
|
+
* "settings.dark": true,
|
1999
|
+
* "settings.plan": "free"
|
2000
|
+
* }
|
1996
2001
|
* }
|
1997
2002
|
* ```
|
1998
2003
|
*
|
@@ -2003,11 +2008,11 @@ declare type QueryTableVariables = {
|
|
2003
2008
|
* ```json
|
2004
2009
|
* {
|
2005
2010
|
* "filter": {
|
2006
|
-
*
|
2007
|
-
*
|
2008
|
-
*
|
2009
|
-
*
|
2010
|
-
* }
|
2011
|
+
* "$any": {
|
2012
|
+
* "settings.dark": true,
|
2013
|
+
* "settings.plan": "free"
|
2014
|
+
* }
|
2015
|
+
* }
|
2011
2016
|
* }
|
2012
2017
|
* ```
|
2013
2018
|
*
|
@@ -2018,10 +2023,10 @@ declare type QueryTableVariables = {
|
|
2018
2023
|
* "filter": {
|
2019
2024
|
* "$any": [
|
2020
2025
|
* {
|
2021
|
-
* "name": "r1"
|
2026
|
+
* "name": "r1"
|
2022
2027
|
* },
|
2023
2028
|
* {
|
2024
|
-
* "name": "r2"
|
2029
|
+
* "name": "r2"
|
2025
2030
|
* }
|
2026
2031
|
* ]
|
2027
2032
|
* }
|
@@ -2033,7 +2038,7 @@ declare type QueryTableVariables = {
|
|
2033
2038
|
* ```json
|
2034
2039
|
* {
|
2035
2040
|
* "filter": {
|
2036
|
-
* "$exists": "settings"
|
2041
|
+
* "$exists": "settings"
|
2037
2042
|
* }
|
2038
2043
|
* }
|
2039
2044
|
* ```
|
@@ -2045,10 +2050,10 @@ declare type QueryTableVariables = {
|
|
2045
2050
|
* "filter": {
|
2046
2051
|
* "$all": [
|
2047
2052
|
* {
|
2048
|
-
* "$exists": "settings"
|
2053
|
+
* "$exists": "settings"
|
2049
2054
|
* },
|
2050
2055
|
* {
|
2051
|
-
* "$exists": "name"
|
2056
|
+
* "$exists": "name"
|
2052
2057
|
* }
|
2053
2058
|
* ]
|
2054
2059
|
* }
|
@@ -2060,7 +2065,7 @@ declare type QueryTableVariables = {
|
|
2060
2065
|
* ```json
|
2061
2066
|
* {
|
2062
2067
|
* "filter": {
|
2063
|
-
* "$notExists": "settings"
|
2068
|
+
* "$notExists": "settings"
|
2064
2069
|
* }
|
2065
2070
|
* }
|
2066
2071
|
* ```
|
@@ -2087,7 +2092,7 @@ declare type QueryTableVariables = {
|
|
2087
2092
|
* {
|
2088
2093
|
* "filter": {
|
2089
2094
|
* "<column_name>": {
|
2090
|
-
*
|
2095
|
+
* "$pattern": "v*alue*"
|
2091
2096
|
* }
|
2092
2097
|
* }
|
2093
2098
|
* }
|
@@ -2099,10 +2104,10 @@ declare type QueryTableVariables = {
|
|
2099
2104
|
* {
|
2100
2105
|
* "filter": {
|
2101
2106
|
* "<column_name>": {
|
2102
|
-
*
|
2107
|
+
* "$endsWith": ".gz"
|
2103
2108
|
* },
|
2104
2109
|
* "<column_name>": {
|
2105
|
-
*
|
2110
|
+
* "$startsWith": "tmp-"
|
2106
2111
|
* }
|
2107
2112
|
* }
|
2108
2113
|
* }
|
@@ -2113,17 +2118,16 @@ declare type QueryTableVariables = {
|
|
2113
2118
|
* ```json
|
2114
2119
|
* {
|
2115
2120
|
* "filter": {
|
2116
|
-
*
|
2117
|
-
*
|
2118
|
-
*
|
2119
|
-
*
|
2121
|
+
* "<column_name>": {
|
2122
|
+
* "$ge": 0,
|
2123
|
+
* "$lt": 100
|
2124
|
+
* }
|
2120
2125
|
* }
|
2121
2126
|
* }
|
2122
2127
|
* ```
|
2123
2128
|
*
|
2124
2129
|
* The supported operators are `$gt`, `$lt`, `$ge`, `$le`.
|
2125
2130
|
*
|
2126
|
-
*
|
2127
2131
|
* #### Negations
|
2128
2132
|
*
|
2129
2133
|
* A general `$not` operator can inverse any operation.
|
@@ -2148,15 +2152,21 @@ declare type QueryTableVariables = {
|
|
2148
2152
|
* {
|
2149
2153
|
* "filter": {
|
2150
2154
|
* "$not": {
|
2151
|
-
* "$any": [
|
2152
|
-
*
|
2153
|
-
*
|
2154
|
-
*
|
2155
|
-
*
|
2156
|
-
*
|
2157
|
-
*
|
2158
|
-
*
|
2159
|
-
*
|
2155
|
+
* "$any": [
|
2156
|
+
* {
|
2157
|
+
* "<column_name1>": "value1"
|
2158
|
+
* },
|
2159
|
+
* {
|
2160
|
+
* "$all": [
|
2161
|
+
* {
|
2162
|
+
* "<column_name2>": "value2"
|
2163
|
+
* },
|
2164
|
+
* {
|
2165
|
+
* "<column_name3>": "value3"
|
2166
|
+
* }
|
2167
|
+
* ]
|
2168
|
+
* }
|
2169
|
+
* ]
|
2160
2170
|
* }
|
2161
2171
|
* }
|
2162
2172
|
* }
|
@@ -2211,8 +2221,8 @@ declare type QueryTableVariables = {
|
|
2211
2221
|
* "<array name>": {
|
2212
2222
|
* "$includes": {
|
2213
2223
|
* "$all": [
|
2214
|
-
* {"$contains": "label"},
|
2215
|
-
* {"$not": {"$endsWith": "-debug"}}
|
2224
|
+
* { "$contains": "label" },
|
2225
|
+
* { "$not": { "$endsWith": "-debug" } }
|
2216
2226
|
* ]
|
2217
2227
|
* }
|
2218
2228
|
* }
|
@@ -2232,9 +2242,7 @@ declare type QueryTableVariables = {
|
|
2232
2242
|
* {
|
2233
2243
|
* "filter": {
|
2234
2244
|
* "settings.labels": {
|
2235
|
-
* "$includesAll": [
|
2236
|
-
* {"$contains": "label"},
|
2237
|
-
* ]
|
2245
|
+
* "$includesAll": [{ "$contains": "label" }]
|
2238
2246
|
* }
|
2239
2247
|
* }
|
2240
2248
|
* }
|
@@ -2282,7 +2290,6 @@ declare type QueryTableVariables = {
|
|
2282
2290
|
* }
|
2283
2291
|
* ```
|
2284
2292
|
*
|
2285
|
-
*
|
2286
2293
|
* ### Pagination
|
2287
2294
|
*
|
2288
2295
|
* We offer cursor pagination and offset pagination. The offset pagination is limited
|
@@ -2348,8 +2355,8 @@ declare type QueryTableVariables = {
|
|
2348
2355
|
* can be queried by update `page.after` to the returned cursor while keeping the
|
2349
2356
|
* `page.before` cursor from the first range query.
|
2350
2357
|
*
|
2351
|
-
* The `filter` , `columns`,
|
2352
|
-
* encoded with the cursor.
|
2358
|
+
* The `filter` , `columns`, `sort` , and `page.size` configuration will be
|
2359
|
+
* encoded with the cursor. The pagination request will be invalid if
|
2353
2360
|
* `filter` or `sort` is set. The columns returned and page size can be changed
|
2354
2361
|
* anytime by passing the `columns` or `page.size` settings to the next query.
|
2355
2362
|
*
|
@@ -2793,7 +2800,7 @@ declare type QueryOptions<T extends XataRecord> = {
|
|
2793
2800
|
columns?: NonEmptyArray<SelectableColumn<T>>;
|
2794
2801
|
filter?: FilterExpression;
|
2795
2802
|
sort?: SortFilter<T> | SortFilter<T>[];
|
2796
|
-
|
2803
|
+
cache?: number;
|
2797
2804
|
};
|
2798
2805
|
/**
|
2799
2806
|
* Query objects contain the information of all filters, sorting, etc. to be included in the database query.
|
@@ -2894,6 +2901,12 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
|
|
2894
2901
|
getFirst(): Promise<Result | null>;
|
2895
2902
|
getFirst(options: Omit<QueryOptions<Record>, 'columns' | 'page'>): Promise<Result | null>;
|
2896
2903
|
getFirst<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']> | null>;
|
2904
|
+
/**
|
2905
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2906
|
+
* @param ttl The cache TTL in milliseconds.
|
2907
|
+
* @returns A new Query object.
|
2908
|
+
*/
|
2909
|
+
cache(ttl: number): Query<Record, Result>;
|
2897
2910
|
nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
2898
2911
|
previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
2899
2912
|
firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
@@ -3088,7 +3101,6 @@ declare abstract class Repository<Data extends BaseData, Record extends XataReco
|
|
3088
3101
|
declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> implements Repository<Data, Record> {
|
3089
3102
|
#private;
|
3090
3103
|
db: SchemaPluginResult<any>;
|
3091
|
-
cache: CacheImpl;
|
3092
3104
|
constructor(options: {
|
3093
3105
|
table: string;
|
3094
3106
|
links?: LinkDictionary;
|
@@ -3258,7 +3270,7 @@ declare type BranchResolutionOptions = {
|
|
3258
3270
|
apiKey?: string;
|
3259
3271
|
fetchImpl?: FetchImpl;
|
3260
3272
|
};
|
3261
|
-
declare function getCurrentBranchName(options?: BranchResolutionOptions): Promise<string
|
3273
|
+
declare function getCurrentBranchName(options?: BranchResolutionOptions): Promise<string>;
|
3262
3274
|
declare function getCurrentBranchDetails(options?: BranchResolutionOptions): Promise<DBBranch | null>;
|
3263
3275
|
declare function getDatabaseURL(): string | undefined;
|
3264
3276
|
|
@@ -3269,4 +3281,4 @@ declare class XataError extends Error {
|
|
3269
3281
|
constructor(message: string, status: number);
|
3270
3282
|
}
|
3271
3283
|
|
3272
|
-
export { AcceptWorkspaceMemberInviteError, AcceptWorkspaceMemberInvitePathParams, AcceptWorkspaceMemberInviteVariables, AddTableColumnError, AddTableColumnPathParams, AddTableColumnVariables, BaseClient, BaseClientOptions, BaseData, BulkInsertTableRecordsError, BulkInsertTableRecordsPathParams, BulkInsertTableRecordsRequestBody, BulkInsertTableRecordsResponse, BulkInsertTableRecordsVariables, CacheImpl, CancelWorkspaceMemberInviteError, CancelWorkspaceMemberInvitePathParams, CancelWorkspaceMemberInviteVariables, ClientConstructor, CreateBranchError, CreateBranchPathParams, CreateBranchQueryParams, CreateBranchRequestBody, CreateBranchVariables, CreateDatabaseError, CreateDatabasePathParams, CreateDatabaseRequestBody, CreateDatabaseResponse, CreateDatabaseVariables, CreateTableError, CreateTablePathParams, CreateTableVariables, CreateUserAPIKeyError, CreateUserAPIKeyPathParams, CreateUserAPIKeyResponse, CreateUserAPIKeyVariables, CreateWorkspaceError, CreateWorkspaceVariables, CursorNavigationOptions, DeleteBranchError, DeleteBranchPathParams, DeleteBranchVariables, DeleteColumnError, DeleteColumnPathParams, DeleteColumnVariables, DeleteDatabaseError, DeleteDatabasePathParams, DeleteDatabaseVariables, DeleteRecordError, DeleteRecordPathParams, DeleteRecordVariables, DeleteTableError, DeleteTablePathParams, DeleteTableVariables, DeleteUserAPIKeyError, DeleteUserAPIKeyPathParams, DeleteUserAPIKeyVariables, DeleteUserError, DeleteUserVariables, DeleteWorkspaceError, DeleteWorkspacePathParams, DeleteWorkspaceVariables, EditableData, ExecuteBranchMigrationPlanError, ExecuteBranchMigrationPlanPathParams, ExecuteBranchMigrationPlanRequestBody, ExecuteBranchMigrationPlanVariables, FetchImpl, FetcherExtraProps, GetBranchDetailsError, GetBranchDetailsPathParams, GetBranchDetailsVariables, GetBranchListError, GetBranchListPathParams, GetBranchListVariables, GetBranchMetadataError, GetBranchMetadataPathParams, GetBranchMetadataVariables, GetBranchMigrationHistoryError, GetBranchMigrationHistoryPathParams, GetBranchMigrationHistoryRequestBody, GetBranchMigrationHistoryResponse, GetBranchMigrationHistoryVariables, GetBranchMigrationPlanError, GetBranchMigrationPlanPathParams, GetBranchMigrationPlanVariables, GetBranchStatsError, GetBranchStatsPathParams, GetBranchStatsResponse, GetBranchStatsVariables, GetColumnError, GetColumnPathParams, GetColumnVariables, GetDatabaseListError, GetDatabaseListPathParams, GetDatabaseListVariables, GetRecordError, GetRecordPathParams, GetRecordRequestBody, GetRecordVariables, GetTableColumnsError, GetTableColumnsPathParams, GetTableColumnsResponse, GetTableColumnsVariables, GetTableSchemaError, GetTableSchemaPathParams, GetTableSchemaResponse, GetTableSchemaVariables, GetUserAPIKeysError, GetUserAPIKeysResponse, GetUserAPIKeysVariables, GetUserError, GetUserVariables, GetWorkspaceError, GetWorkspaceMembersListError, GetWorkspaceMembersListPathParams, GetWorkspaceMembersListVariables, GetWorkspacePathParams, GetWorkspaceVariables, GetWorkspacesListError, GetWorkspacesListResponse, GetWorkspacesListVariables, Identifiable, InsertRecordError, InsertRecordPathParams, InsertRecordResponse, InsertRecordVariables, InsertRecordWithIDError, InsertRecordWithIDPathParams, InsertRecordWithIDQueryParams, InsertRecordWithIDVariables, InviteWorkspaceMemberError, InviteWorkspaceMemberPathParams, InviteWorkspaceMemberRequestBody, InviteWorkspaceMemberVariables, LinkDictionary, OffsetNavigationOptions, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Paginable, PaginationOptions, PaginationQueryMeta, Query, QueryTableError, QueryTablePathParams, QueryTableRequestBody, QueryTableVariables, RemoveWorkspaceMemberError, RemoveWorkspaceMemberPathParams, RemoveWorkspaceMemberVariables, Repository, ResendWorkspaceMemberInviteError, ResendWorkspaceMemberInvitePathParams, ResendWorkspaceMemberInviteVariables, responses as Responses, RestRepository, SchemaDefinition, SchemaPlugin, SchemaPluginResult, schemas as Schemas, SearchBranchError, SearchBranchPathParams, SearchBranchRequestBody, SearchBranchVariables, SearchOptions, SearchPlugin, SearchPluginResult, SelectableColumn, SelectedPick, SetTableSchemaError, SetTableSchemaPathParams, SetTableSchemaRequestBody, SetTableSchemaVariables, SimpleCache, UpdateBranchMetadataError, UpdateBranchMetadataPathParams, UpdateBranchMetadataVariables, UpdateColumnError, UpdateColumnPathParams, UpdateColumnRequestBody, UpdateColumnVariables, UpdateRecordWithIDError, UpdateRecordWithIDPathParams, UpdateRecordWithIDQueryParams, UpdateRecordWithIDVariables, UpdateTableError, UpdateTablePathParams, UpdateTableRequestBody, UpdateTableVariables, UpdateUserError, UpdateUserVariables, UpdateWorkspaceError, UpdateWorkspaceMemberRoleError, UpdateWorkspaceMemberRolePathParams, UpdateWorkspaceMemberRoleRequestBody, UpdateWorkspaceMemberRoleVariables, UpdateWorkspacePathParams, UpdateWorkspaceVariables, UpsertRecordWithIDError, UpsertRecordWithIDPathParams, UpsertRecordWithIDQueryParams, UpsertRecordWithIDVariables, ValueAtColumn, XataApiClient, XataApiClientOptions, XataApiPlugin, XataError, XataPlugin, XataPluginOptions, XataRecord, acceptWorkspaceMemberInvite, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeWorkspaceMember, resendWorkspaceMemberInvite, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
3284
|
+
export { AcceptWorkspaceMemberInviteError, AcceptWorkspaceMemberInvitePathParams, AcceptWorkspaceMemberInviteVariables, AddTableColumnError, AddTableColumnPathParams, AddTableColumnVariables, BaseClient, BaseClientOptions, BaseData, BulkInsertTableRecordsError, BulkInsertTableRecordsPathParams, BulkInsertTableRecordsRequestBody, BulkInsertTableRecordsResponse, BulkInsertTableRecordsVariables, CacheImpl, CancelWorkspaceMemberInviteError, CancelWorkspaceMemberInvitePathParams, CancelWorkspaceMemberInviteVariables, ClientConstructor, CreateBranchError, CreateBranchPathParams, CreateBranchQueryParams, CreateBranchRequestBody, CreateBranchVariables, CreateDatabaseError, CreateDatabasePathParams, CreateDatabaseRequestBody, CreateDatabaseResponse, CreateDatabaseVariables, CreateTableError, CreateTablePathParams, CreateTableVariables, CreateUserAPIKeyError, CreateUserAPIKeyPathParams, CreateUserAPIKeyResponse, CreateUserAPIKeyVariables, CreateWorkspaceError, CreateWorkspaceVariables, CursorNavigationOptions, DeleteBranchError, DeleteBranchPathParams, DeleteBranchVariables, DeleteColumnError, DeleteColumnPathParams, DeleteColumnVariables, DeleteDatabaseError, DeleteDatabasePathParams, DeleteDatabaseVariables, DeleteRecordError, DeleteRecordPathParams, DeleteRecordVariables, DeleteTableError, DeleteTablePathParams, DeleteTableVariables, DeleteUserAPIKeyError, DeleteUserAPIKeyPathParams, DeleteUserAPIKeyVariables, DeleteUserError, DeleteUserVariables, DeleteWorkspaceError, DeleteWorkspacePathParams, DeleteWorkspaceVariables, EditableData, ExecuteBranchMigrationPlanError, ExecuteBranchMigrationPlanPathParams, ExecuteBranchMigrationPlanRequestBody, ExecuteBranchMigrationPlanVariables, FetchImpl, FetcherExtraProps, GetBranchDetailsError, GetBranchDetailsPathParams, GetBranchDetailsVariables, GetBranchListError, GetBranchListPathParams, GetBranchListVariables, GetBranchMetadataError, GetBranchMetadataPathParams, GetBranchMetadataVariables, GetBranchMigrationHistoryError, GetBranchMigrationHistoryPathParams, GetBranchMigrationHistoryRequestBody, GetBranchMigrationHistoryResponse, GetBranchMigrationHistoryVariables, GetBranchMigrationPlanError, GetBranchMigrationPlanPathParams, GetBranchMigrationPlanVariables, GetBranchStatsError, GetBranchStatsPathParams, GetBranchStatsResponse, GetBranchStatsVariables, GetColumnError, GetColumnPathParams, GetColumnVariables, GetDatabaseListError, GetDatabaseListPathParams, GetDatabaseListVariables, GetRecordError, GetRecordPathParams, GetRecordRequestBody, GetRecordVariables, GetTableColumnsError, GetTableColumnsPathParams, GetTableColumnsResponse, GetTableColumnsVariables, GetTableSchemaError, GetTableSchemaPathParams, GetTableSchemaResponse, GetTableSchemaVariables, GetUserAPIKeysError, GetUserAPIKeysResponse, GetUserAPIKeysVariables, GetUserError, GetUserVariables, GetWorkspaceError, GetWorkspaceMembersListError, GetWorkspaceMembersListPathParams, GetWorkspaceMembersListVariables, GetWorkspacePathParams, GetWorkspaceVariables, GetWorkspacesListError, GetWorkspacesListResponse, GetWorkspacesListVariables, Identifiable, InsertRecordError, InsertRecordPathParams, InsertRecordResponse, InsertRecordVariables, InsertRecordWithIDError, InsertRecordWithIDPathParams, InsertRecordWithIDQueryParams, InsertRecordWithIDVariables, InviteWorkspaceMemberError, InviteWorkspaceMemberPathParams, InviteWorkspaceMemberRequestBody, InviteWorkspaceMemberVariables, LinkDictionary, OffsetNavigationOptions, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Paginable, PaginationOptions, PaginationQueryMeta, Query, QueryTableError, QueryTablePathParams, QueryTableRequestBody, QueryTableVariables, RemoveWorkspaceMemberError, RemoveWorkspaceMemberPathParams, RemoveWorkspaceMemberVariables, Repository, ResendWorkspaceMemberInviteError, ResendWorkspaceMemberInvitePathParams, ResendWorkspaceMemberInviteVariables, responses as Responses, RestRepository, SchemaDefinition, SchemaPlugin, SchemaPluginResult, schemas as Schemas, SearchBranchError, SearchBranchPathParams, SearchBranchRequestBody, SearchBranchVariables, SearchOptions, SearchPlugin, SearchPluginResult, SelectableColumn, SelectedPick, SetTableSchemaError, SetTableSchemaPathParams, SetTableSchemaRequestBody, SetTableSchemaVariables, SimpleCache, SimpleCacheOptions, UpdateBranchMetadataError, UpdateBranchMetadataPathParams, UpdateBranchMetadataVariables, UpdateColumnError, UpdateColumnPathParams, UpdateColumnRequestBody, UpdateColumnVariables, UpdateRecordWithIDError, UpdateRecordWithIDPathParams, UpdateRecordWithIDQueryParams, UpdateRecordWithIDVariables, UpdateTableError, UpdateTablePathParams, UpdateTableRequestBody, UpdateTableVariables, UpdateUserError, UpdateUserVariables, UpdateWorkspaceError, UpdateWorkspaceMemberRoleError, UpdateWorkspaceMemberRolePathParams, UpdateWorkspaceMemberRoleRequestBody, UpdateWorkspaceMemberRoleVariables, UpdateWorkspacePathParams, UpdateWorkspaceVariables, UpsertRecordWithIDError, UpsertRecordWithIDPathParams, UpsertRecordWithIDQueryParams, UpsertRecordWithIDVariables, ValueAtColumn, XataApiClient, XataApiClientOptions, XataApiPlugin, XataError, XataPlugin, XataPluginOptions, XataRecord, acceptWorkspaceMemberInvite, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeWorkspaceMember, resendWorkspaceMemberInvite, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
package/dist/index.mjs
CHANGED
@@ -945,7 +945,7 @@ const _Query = class {
|
|
945
945
|
__privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
|
946
946
|
__privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
|
947
947
|
__privateGet$4(this, _data).page = data.page ?? parent?.page;
|
948
|
-
__privateGet$4(this, _data).
|
948
|
+
__privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
|
949
949
|
this.any = this.any.bind(this);
|
950
950
|
this.all = this.all.bind(this);
|
951
951
|
this.not = this.not.bind(this);
|
@@ -1031,6 +1031,9 @@ const _Query = class {
|
|
1031
1031
|
const records = await this.getMany({ ...options, page: { size: 1 } });
|
1032
1032
|
return records[0] || null;
|
1033
1033
|
}
|
1034
|
+
cache(ttl) {
|
1035
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
|
1036
|
+
}
|
1034
1037
|
nextPage(size, offset) {
|
1035
1038
|
return this.firstPage(size, offset);
|
1036
1039
|
}
|
@@ -1104,7 +1107,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1104
1107
|
__accessCheck$4(obj, member, "access private method");
|
1105
1108
|
return method;
|
1106
1109
|
};
|
1107
|
-
var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn;
|
1110
|
+
var _table, _links, _getFetchProps, _cache, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn;
|
1108
1111
|
class Repository extends Query {
|
1109
1112
|
}
|
1110
1113
|
class RestRepository extends Query {
|
@@ -1124,11 +1127,12 @@ class RestRepository extends Query {
|
|
1124
1127
|
__privateAdd$4(this, _table, void 0);
|
1125
1128
|
__privateAdd$4(this, _links, void 0);
|
1126
1129
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1130
|
+
__privateAdd$4(this, _cache, void 0);
|
1127
1131
|
__privateSet$2(this, _table, options.table);
|
1128
1132
|
__privateSet$2(this, _links, options.links ?? {});
|
1129
1133
|
__privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1130
1134
|
this.db = options.db;
|
1131
|
-
this
|
1135
|
+
__privateSet$2(this, _cache, options.pluginOptions.cache);
|
1132
1136
|
}
|
1133
1137
|
async create(a, b) {
|
1134
1138
|
if (Array.isArray(a)) {
|
@@ -1271,6 +1275,7 @@ class RestRepository extends Query {
|
|
1271
1275
|
_table = new WeakMap();
|
1272
1276
|
_links = new WeakMap();
|
1273
1277
|
_getFetchProps = new WeakMap();
|
1278
|
+
_cache = new WeakMap();
|
1274
1279
|
_insertRecordWithoutId = new WeakSet();
|
1275
1280
|
insertRecordWithoutId_fn = async function(object) {
|
1276
1281
|
const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
|
@@ -1363,34 +1368,38 @@ deleteRecord_fn = async function(recordId) {
|
|
1363
1368
|
};
|
1364
1369
|
_invalidateCache = new WeakSet();
|
1365
1370
|
invalidateCache_fn = async function(recordId) {
|
1366
|
-
await this.
|
1367
|
-
const cacheItems = await this.
|
1371
|
+
await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
|
1372
|
+
const cacheItems = await __privateGet$3(this, _cache).getAll();
|
1368
1373
|
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1369
1374
|
for (const [key, value] of queries) {
|
1370
1375
|
const ids = getIds(value);
|
1371
1376
|
if (ids.includes(recordId))
|
1372
|
-
await this.
|
1377
|
+
await __privateGet$3(this, _cache).delete(key);
|
1373
1378
|
}
|
1374
1379
|
};
|
1375
1380
|
_setCacheRecord = new WeakSet();
|
1376
1381
|
setCacheRecord_fn = async function(record) {
|
1377
|
-
|
1382
|
+
if (!__privateGet$3(this, _cache).cacheRecords)
|
1383
|
+
return;
|
1384
|
+
await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
|
1378
1385
|
};
|
1379
1386
|
_getCacheRecord = new WeakSet();
|
1380
1387
|
getCacheRecord_fn = async function(recordId) {
|
1381
|
-
|
1388
|
+
if (!__privateGet$3(this, _cache).cacheRecords)
|
1389
|
+
return null;
|
1390
|
+
return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
|
1382
1391
|
};
|
1383
1392
|
_setCacheQuery = new WeakSet();
|
1384
1393
|
setCacheQuery_fn = async function(query, meta, records) {
|
1385
|
-
await this.
|
1394
|
+
await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
1386
1395
|
};
|
1387
1396
|
_getCacheQuery = new WeakSet();
|
1388
1397
|
getCacheQuery_fn = async function(query) {
|
1389
1398
|
const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
|
1390
|
-
const result = await this.
|
1399
|
+
const result = await __privateGet$3(this, _cache).get(key);
|
1391
1400
|
if (!result)
|
1392
1401
|
return null;
|
1393
|
-
const { ttl =
|
1402
|
+
const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
|
1394
1403
|
if (!ttl || ttl < 0)
|
1395
1404
|
return result;
|
1396
1405
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -1459,9 +1468,12 @@ var __privateSet$1 = (obj, member, value, setter) => {
|
|
1459
1468
|
};
|
1460
1469
|
var _map;
|
1461
1470
|
class SimpleCache {
|
1462
|
-
constructor() {
|
1471
|
+
constructor(options = {}) {
|
1463
1472
|
__privateAdd$3(this, _map, void 0);
|
1464
1473
|
__privateSet$1(this, _map, /* @__PURE__ */ new Map());
|
1474
|
+
this.capacity = options.max ?? 500;
|
1475
|
+
this.cacheRecords = options.cacheRecords ?? true;
|
1476
|
+
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1465
1477
|
}
|
1466
1478
|
async getAll() {
|
1467
1479
|
return Object.fromEntries(__privateGet$2(this, _map));
|
@@ -1470,7 +1482,12 @@ class SimpleCache {
|
|
1470
1482
|
return __privateGet$2(this, _map).get(key) ?? null;
|
1471
1483
|
}
|
1472
1484
|
async set(key, value) {
|
1485
|
+
await this.delete(key);
|
1473
1486
|
__privateGet$2(this, _map).set(key, value);
|
1487
|
+
if (__privateGet$2(this, _map).size > this.capacity) {
|
1488
|
+
const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
|
1489
|
+
await this.delete(leastRecentlyUsed);
|
1490
|
+
}
|
1474
1491
|
}
|
1475
1492
|
async delete(key) {
|
1476
1493
|
__privateGet$2(this, _map).delete(key);
|
@@ -1733,7 +1750,7 @@ const buildClient = (plugins) => {
|
|
1733
1750
|
const fetch = getFetchImplementation(options?.fetch);
|
1734
1751
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1735
1752
|
const apiKey = options?.apiKey || getAPIKey();
|
1736
|
-
const cache = options?.cache ?? new SimpleCache();
|
1753
|
+
const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
|
1737
1754
|
const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1738
1755
|
if (!databaseURL || !apiKey) {
|
1739
1756
|
throw new Error("Options databaseURL and apiKey are required");
|