@xata.io/client 0.13.1 → 0.13.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/CHANGELOG.md +10 -0
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.mjs +12 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -6,6 +6,9 @@ declare type FetchImpl = (url: string, init?: {
|
|
6
6
|
ok: boolean;
|
7
7
|
status: number;
|
8
8
|
json(): Promise<any>;
|
9
|
+
headers?: {
|
10
|
+
get(name: string): string | null;
|
11
|
+
};
|
9
12
|
}>;
|
10
13
|
declare type WorkspaceApiUrlBuilder = (path: string, pathParams: Record<string, string>) => string;
|
11
14
|
declare type FetcherExtraProps = {
|
@@ -2867,25 +2870,24 @@ declare type SelectableColumn<O, RecursivePath extends any[] = []> = '*' | 'id'
|
|
2867
2870
|
declare type SelectedPick<O extends XataRecord, Key extends SelectableColumn<O>[]> = XataRecord & UnionToIntersection<Values<{
|
2868
2871
|
[K in Key[number]]: NestedValueAtColumn<O, K> & XataRecord;
|
2869
2872
|
}>>;
|
2870
|
-
declare type ValueAtColumn<O, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<
|
2871
|
-
V: ValueAtColumn<
|
2872
|
-
} : never : O[K]> : never : never;
|
2873
|
+
declare type ValueAtColumn<O, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<NonNullable<O[K]> extends infer Item ? Item extends Record<string, any> ? V extends SelectableColumn<Item> ? {
|
2874
|
+
V: ValueAtColumn<Item, V>;
|
2875
|
+
} : never : O[K] : never> : never : never;
|
2873
2876
|
declare type MAX_RECURSION = 5;
|
2874
2877
|
declare type NestedColumns<O, RecursivePath extends any[]> = RecursivePath['length'] extends MAX_RECURSION ? never : If<IsObject<O>, Values<{
|
2875
|
-
[K in DataProps<O>]:
|
2876
|
-
If<IsObject<
|
2877
|
-
K
|
2878
|
+
[K in DataProps<O>]: NonNullable<O[K]> extends infer Item ? If<IsArray<Item>, K, // If the property is an array, we stop recursion. We don't support object arrays yet
|
2879
|
+
If<IsObject<Item>, Item extends XataRecord ? SelectableColumn<Item, [...RecursivePath, Item]> extends infer Column ? Column extends string ? K | `${K}.${Column}` : never : never : Item extends Date ? K : `${K}.${StringKeys<Item> | '*'}`, // This allows usage of objects that are not links
|
2880
|
+
K>> : never;
|
2878
2881
|
}>, never>;
|
2879
2882
|
declare type DataProps<O> = Exclude<StringKeys<O>, StringKeys<XataRecord>>;
|
2880
2883
|
declare type NestedValueAtColumn<O, Key extends SelectableColumn<O>> = Key extends `${infer N}.${infer M}` ? N extends DataProps<O> ? {
|
2881
|
-
[K in N]: M extends SelectableColumn<
|
2884
|
+
[K in N]: M extends SelectableColumn<NonNullable<O[K]>> ? NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M> & XataRecord> : ForwardNullable<O[K], NestedValueAtColumn<NonNullable<O[K]>, M>> : unknown;
|
2882
2885
|
} : unknown : Key extends DataProps<O> ? {
|
2883
|
-
[K in Key]:
|
2886
|
+
[K in Key]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], SelectedPick<NonNullable<O[K]>, ['*']>> : O[K];
|
2884
2887
|
} : Key extends '*' ? {
|
2885
|
-
[K in StringKeys<O>]:
|
2888
|
+
[K in StringKeys<O>]: NonNullable<O[K]> extends XataRecord ? ForwardNullable<O[K], Link<NonNullable<O[K]>>> : O[K];
|
2886
2889
|
} : unknown;
|
2887
|
-
declare type
|
2888
|
-
declare type ForwardNullable<T, R> = T extends RemoveNullable<T> ? R : R | null;
|
2890
|
+
declare type ForwardNullable<T, R> = T extends NonNullable<T> ? R : R | null;
|
2889
2891
|
|
2890
2892
|
/**
|
2891
2893
|
* Represents an identifiable record from the database.
|
package/dist/index.mjs
CHANGED
@@ -17,7 +17,8 @@ function toBase64(value) {
|
|
17
17
|
try {
|
18
18
|
return btoa(value);
|
19
19
|
} catch (err) {
|
20
|
-
|
20
|
+
const buf = Buffer;
|
21
|
+
return buf.from(value).toString("base64");
|
21
22
|
}
|
22
23
|
}
|
23
24
|
|
@@ -73,7 +74,7 @@ function getFetchImplementation(userFetch) {
|
|
73
74
|
return fetchImpl;
|
74
75
|
}
|
75
76
|
|
76
|
-
const VERSION = "0.13.
|
77
|
+
const VERSION = "0.13.2";
|
77
78
|
|
78
79
|
class ErrorWithCause extends Error {
|
79
80
|
constructor(message, options) {
|
@@ -81,15 +82,20 @@ class ErrorWithCause extends Error {
|
|
81
82
|
}
|
82
83
|
}
|
83
84
|
class FetcherError extends ErrorWithCause {
|
84
|
-
constructor(status, data) {
|
85
|
+
constructor(status, data, requestId) {
|
85
86
|
super(getMessage(data));
|
86
87
|
this.status = status;
|
87
88
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
89
|
+
this.requestId = requestId;
|
88
90
|
if (data instanceof Error) {
|
89
91
|
this.stack = data.stack;
|
90
92
|
this.cause = data.cause;
|
91
93
|
}
|
92
94
|
}
|
95
|
+
toString() {
|
96
|
+
const error = super.toString();
|
97
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
98
|
+
}
|
93
99
|
}
|
94
100
|
function isBulkError(error) {
|
95
101
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -166,14 +172,15 @@ async function fetch$1({
|
|
166
172
|
if (response.status === 204) {
|
167
173
|
return {};
|
168
174
|
}
|
175
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
169
176
|
try {
|
170
177
|
const jsonResponse = await response.json();
|
171
178
|
if (response.ok) {
|
172
179
|
return jsonResponse;
|
173
180
|
}
|
174
|
-
throw new FetcherError(response.status, jsonResponse);
|
181
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
175
182
|
} catch (error) {
|
176
|
-
throw new FetcherError(response.status, error);
|
183
|
+
throw new FetcherError(response.status, error, requestId);
|
177
184
|
}
|
178
185
|
}
|
179
186
|
|