@xata.io/client 0.0.0-alpha.vf4789c2 → 0.0.0-alpha.vf603f80
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 +87 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.mjs +84 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -145,7 +145,7 @@ function getFetchImplementation(userFetch) {
|
|
145
145
|
return fetchImpl;
|
146
146
|
}
|
147
147
|
|
148
|
-
const VERSION = "0.0.0-alpha.
|
148
|
+
const VERSION = "0.0.0-alpha.vf603f80";
|
149
149
|
|
150
150
|
class ErrorWithCause extends Error {
|
151
151
|
constructor(message, options) {
|
@@ -2105,6 +2105,88 @@ const buildClient = (plugins) => {
|
|
2105
2105
|
class BaseClient extends buildClient() {
|
2106
2106
|
}
|
2107
2107
|
|
2108
|
+
const META = "__";
|
2109
|
+
const VALUE = "___";
|
2110
|
+
class Serializer {
|
2111
|
+
constructor() {
|
2112
|
+
this.classes = {};
|
2113
|
+
}
|
2114
|
+
add(clazz) {
|
2115
|
+
this.classes[clazz.name] = clazz;
|
2116
|
+
}
|
2117
|
+
toJSON(data) {
|
2118
|
+
function visit(obj) {
|
2119
|
+
if (Array.isArray(obj))
|
2120
|
+
return obj.map(visit);
|
2121
|
+
const type = typeof obj;
|
2122
|
+
if (type === "undefined")
|
2123
|
+
return { [META]: "undefined" };
|
2124
|
+
if (type === "bigint")
|
2125
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2126
|
+
if (obj === null || type !== "object")
|
2127
|
+
return obj;
|
2128
|
+
const constructor = obj.constructor;
|
2129
|
+
const o = { [META]: constructor.name };
|
2130
|
+
for (const [key, value] of Object.entries(obj)) {
|
2131
|
+
o[key] = visit(value);
|
2132
|
+
}
|
2133
|
+
if (constructor === Date)
|
2134
|
+
o[VALUE] = obj.toISOString();
|
2135
|
+
if (constructor === Map)
|
2136
|
+
o[VALUE] = Object.fromEntries(obj);
|
2137
|
+
if (constructor === Set)
|
2138
|
+
o[VALUE] = [...obj];
|
2139
|
+
return o;
|
2140
|
+
}
|
2141
|
+
return JSON.stringify(visit(data));
|
2142
|
+
}
|
2143
|
+
fromJSON(json) {
|
2144
|
+
return JSON.parse(json, (key, value) => {
|
2145
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2146
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2147
|
+
const constructor = this.classes[clazz];
|
2148
|
+
if (constructor) {
|
2149
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2150
|
+
}
|
2151
|
+
if (clazz === "Date")
|
2152
|
+
return new Date(val);
|
2153
|
+
if (clazz === "Set")
|
2154
|
+
return new Set(val);
|
2155
|
+
if (clazz === "Map")
|
2156
|
+
return new Map(Object.entries(val));
|
2157
|
+
if (clazz === "bigint")
|
2158
|
+
return BigInt(val);
|
2159
|
+
if (clazz === "undefined")
|
2160
|
+
return void 0;
|
2161
|
+
return rest;
|
2162
|
+
}
|
2163
|
+
return value;
|
2164
|
+
});
|
2165
|
+
}
|
2166
|
+
}
|
2167
|
+
const serialize = () => {
|
2168
|
+
throw new Error("Not implemented");
|
2169
|
+
};
|
2170
|
+
const deserialize = () => {
|
2171
|
+
throw new Error("Not implemented");
|
2172
|
+
};
|
2173
|
+
|
2174
|
+
function buildWorkerRunner(config) {
|
2175
|
+
return function xataWorker(name, _worker) {
|
2176
|
+
return async (...args) => {
|
2177
|
+
const result = await fetch("http://localhost:64749", {
|
2178
|
+
method: "POST",
|
2179
|
+
headers: { "Content-Type": "application/json" },
|
2180
|
+
body: JSON.stringify({
|
2181
|
+
name,
|
2182
|
+
payload: args
|
2183
|
+
})
|
2184
|
+
});
|
2185
|
+
return result.json();
|
2186
|
+
};
|
2187
|
+
};
|
2188
|
+
}
|
2189
|
+
|
2108
2190
|
class XataError extends Error {
|
2109
2191
|
constructor(message, status) {
|
2110
2192
|
super(message);
|
@@ -2125,6 +2207,7 @@ exports.Repository = Repository;
|
|
2125
2207
|
exports.RestRepository = RestRepository;
|
2126
2208
|
exports.SchemaPlugin = SchemaPlugin;
|
2127
2209
|
exports.SearchPlugin = SearchPlugin;
|
2210
|
+
exports.Serializer = Serializer;
|
2128
2211
|
exports.SimpleCache = SimpleCache;
|
2129
2212
|
exports.XataApiClient = XataApiClient;
|
2130
2213
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2134,6 +2217,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
2134
2217
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2135
2218
|
exports.addTableColumn = addTableColumn;
|
2136
2219
|
exports.buildClient = buildClient;
|
2220
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2137
2221
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2138
2222
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2139
2223
|
exports.contains = contains;
|
@@ -2150,6 +2234,7 @@ exports.deleteTable = deleteTable;
|
|
2150
2234
|
exports.deleteUser = deleteUser;
|
2151
2235
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2152
2236
|
exports.deleteWorkspace = deleteWorkspace;
|
2237
|
+
exports.deserialize = deserialize;
|
2153
2238
|
exports.endsWith = endsWith;
|
2154
2239
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2155
2240
|
exports.exists = exists;
|
@@ -2202,6 +2287,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2202
2287
|
exports.resolveBranch = resolveBranch;
|
2203
2288
|
exports.searchBranch = searchBranch;
|
2204
2289
|
exports.searchTable = searchTable;
|
2290
|
+
exports.serialize = serialize;
|
2205
2291
|
exports.setTableSchema = setTableSchema;
|
2206
2292
|
exports.startsWith = startsWith;
|
2207
2293
|
exports.updateBranchMetadata = updateBranchMetadata;
|