@omnistreamai/data-adapter-webdav 0.3.5 → 0.3.7
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.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/webdav-adapter.test.ts +122 -89
- package/src/webdav-adapter.ts +111 -62
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -32,7 +32,7 @@ declare class WebDAVAdapter implements RemoteAdapter {
|
|
|
32
32
|
/**
|
|
33
33
|
* Add data
|
|
34
34
|
*/
|
|
35
|
-
add<T extends Record<string, unknown>>(storeName: string, data: T,
|
|
35
|
+
add<T extends Record<string, unknown>>(storeName: string, data: T, _idKey?: string): Promise<T>;
|
|
36
36
|
/**
|
|
37
37
|
* Update data
|
|
38
38
|
*/
|
|
@@ -40,11 +40,11 @@ declare class WebDAVAdapter implements RemoteAdapter {
|
|
|
40
40
|
/**
|
|
41
41
|
* Delete data
|
|
42
42
|
*/
|
|
43
|
-
delete(storeName: string, id: string,
|
|
43
|
+
delete(storeName: string, id: string, idKey?: string): Promise<void>;
|
|
44
44
|
/**
|
|
45
45
|
* Get data by ID
|
|
46
46
|
*/
|
|
47
|
-
getData<T extends Record<string, unknown>>(storeName: string, id: string,
|
|
47
|
+
getData<T extends Record<string, unknown>>(storeName: string, id: string, idKey?: string): Promise<T | null>;
|
|
48
48
|
/**
|
|
49
49
|
* Get list data (with pagination support)
|
|
50
50
|
*/
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/webdav-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;AACe,cADF,aAAA,YAAyB,aACvB,CAAA;EAQO,SAAA,IAAA,GARP,WAAA,CAAA,MAAA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/webdav-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;AACe,cADF,aAAA,YAAyB,aACvB,CAAA;EAQO,SAAA,IAAA,GARP,WAAA,CAAA,MAAA;EAgHV,SAAA,IAAA,GAAA,eAAA;EAsDiB,QAAA,OAAA;EAEZ;;;EAyBe,UAAA,CAAA,OAAA,EAzLH,aAyLG,CAAA,EAAA,IAAA;EAGP;;;EAEb,QAAA,UAAA;EAiCA;;;EA+BA,QAAA,QAAA;EAoBqB;;;EAIG,QAAA,OAAA;EAAhB;;;EAoH6B,SAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAlSrC,OAkSqC,CAAA,IAAA,CAAA;EAiDhB;;;gBA7RJ,kDAEZ,qBAEL,QAAQ;;;;mBAuBY,8DAGf,QAAQ,qBAEb,QAAQ;;;;yDAiCR;;;;oBA2BqB,yEAIrB,QAAQ;;;;oBAoBa,sDAEb,aAAa,sBAErB,QAAQ,gBAAgB;;;;;;;;;;;;4BAwGK;;;;gCAYQ;;;;oBAiDhB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ declare class WebDAVAdapter implements RemoteAdapter {
|
|
|
32
32
|
/**
|
|
33
33
|
* Add data
|
|
34
34
|
*/
|
|
35
|
-
add<T extends Record<string, unknown>>(storeName: string, data: T,
|
|
35
|
+
add<T extends Record<string, unknown>>(storeName: string, data: T, _idKey?: string): Promise<T>;
|
|
36
36
|
/**
|
|
37
37
|
* Update data
|
|
38
38
|
*/
|
|
@@ -40,11 +40,11 @@ declare class WebDAVAdapter implements RemoteAdapter {
|
|
|
40
40
|
/**
|
|
41
41
|
* Delete data
|
|
42
42
|
*/
|
|
43
|
-
delete(storeName: string, id: string,
|
|
43
|
+
delete(storeName: string, id: string, idKey?: string): Promise<void>;
|
|
44
44
|
/**
|
|
45
45
|
* Get data by ID
|
|
46
46
|
*/
|
|
47
|
-
getData<T extends Record<string, unknown>>(storeName: string, id: string,
|
|
47
|
+
getData<T extends Record<string, unknown>>(storeName: string, id: string, idKey?: string): Promise<T | null>;
|
|
48
48
|
/**
|
|
49
49
|
* Get list data (with pagination support)
|
|
50
50
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/webdav-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;AACe,cADF,aAAA,YAAyB,aACvB,CAAA;EAQO,SAAA,IAAA,GARP,WAAA,CAAA,MAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/webdav-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;AAYA;AACe,cADF,aAAA,YAAyB,aACvB,CAAA;EAQO,SAAA,IAAA,GARP,WAAA,CAAA,MAAA;EAgHV,SAAA,IAAA,GAAA,eAAA;EAsDiB,QAAA,OAAA;EAEZ;;;EAyBe,UAAA,CAAA,OAAA,EAzLH,aAyLG,CAAA,EAAA,IAAA;EAGP;;;EAEb,QAAA,UAAA;EAiCA;;;EA+BA,QAAA,QAAA;EAoBqB;;;EAIG,QAAA,OAAA;EAAhB;;;EAoH6B,SAAA,CAAA,SAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAAA,MAAA,EAAA,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAlSrC,OAkSqC,CAAA,IAAA,CAAA;EAiDhB;;;gBA7RJ,kDAEZ,qBAEL,QAAQ;;;;mBAuBY,8DAGf,QAAQ,qBAEb,QAAQ;;;;yDAiCR;;;;oBA2BqB,yEAIrB,QAAQ;;;;oBAoBa,sDAEb,aAAa,sBAErB,QAAQ,gBAAgB;;;;;;;;;;;;4BAwGK;;;;gCAYQ;;;;oBAiDhB"}
|
package/dist/index.js
CHANGED
|
@@ -37,12 +37,9 @@ var WebDAVAdapter = class {
|
|
|
37
37
|
/**
|
|
38
38
|
* Build URL
|
|
39
39
|
*/
|
|
40
|
-
buildUrl(storeName
|
|
40
|
+
buildUrl(storeName) {
|
|
41
41
|
if (!this.service) throw new Error("Service not configured. Call setService() first.");
|
|
42
|
-
|
|
43
|
-
const storePath = `/${storeName}`;
|
|
44
|
-
if (id) return `${baseUrl}${storePath}/${id}`;
|
|
45
|
-
return `${baseUrl}${storePath}`;
|
|
42
|
+
return `${this.service.endpoint.replace(/\/$/, "")}${this.service.basePath ? `/${this.service.basePath.replace(/^\/+|\/+$/g, "")}` : ""}/${storeName}.json`;
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
45
|
* Send request
|
|
@@ -71,73 +68,97 @@ var WebDAVAdapter = class {
|
|
|
71
68
|
* Initialize store
|
|
72
69
|
*/
|
|
73
70
|
async initStore(storeName, _indexes = [], _idKey = "id") {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
if (!this.service) throw new Error("Service not configured. Call setService() first.");
|
|
72
|
+
if (this.service.basePath) {
|
|
73
|
+
const parts = this.service.basePath.replace(/^\/+|\/+$/g, "").split("/");
|
|
74
|
+
const baseUrl = this.service.endpoint.replace(/\/$/, "");
|
|
75
|
+
let currentPath = "";
|
|
76
|
+
for (const part of parts) {
|
|
77
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
78
|
+
try {
|
|
79
|
+
await this.listDirectory(currentPath);
|
|
80
|
+
} catch {
|
|
81
|
+
const url = `${baseUrl}/${currentPath}`;
|
|
82
|
+
const response = await fetch(url, {
|
|
83
|
+
method: "MKCOL",
|
|
84
|
+
headers: this.getHeaders()
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) throw new Error(`Failed to create base path: ${response.statusText}`);
|
|
87
|
+
}
|
|
87
88
|
}
|
|
88
89
|
}
|
|
90
|
+
const jsonFileUrl = this.buildUrl(storeName);
|
|
91
|
+
if (!await this.request(jsonFileUrl, { method: "GET" }, { allowNotFound: true })) {
|
|
92
|
+
const response = await fetch(jsonFileUrl, {
|
|
93
|
+
method: "PUT",
|
|
94
|
+
headers: this.getHeaders(),
|
|
95
|
+
body: JSON.stringify([])
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok) throw new Error(`Failed to create JSON file: ${response.statusText}`);
|
|
98
|
+
}
|
|
89
99
|
}
|
|
90
100
|
/**
|
|
91
101
|
* Add data
|
|
92
102
|
*/
|
|
93
|
-
async add(storeName, data,
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
103
|
+
async add(storeName, data, _idKey = "id") {
|
|
104
|
+
const url = this.buildUrl(storeName);
|
|
105
|
+
const items = await this.request(url, { method: "GET" }, { allowNotFound: true }) || [];
|
|
106
|
+
items.push(data);
|
|
107
|
+
await this.request(url, {
|
|
97
108
|
method: "PUT",
|
|
98
|
-
body: JSON.stringify(
|
|
99
|
-
})
|
|
109
|
+
body: JSON.stringify(items)
|
|
110
|
+
});
|
|
111
|
+
return data;
|
|
100
112
|
}
|
|
101
113
|
/**
|
|
102
114
|
* Update data
|
|
103
115
|
*/
|
|
104
116
|
async update(storeName, id, data, idKey = "id") {
|
|
105
|
-
const
|
|
117
|
+
const url = this.buildUrl(storeName);
|
|
118
|
+
const existing = await this.request(url, { method: "GET" });
|
|
106
119
|
if (!existing) throw new Error("Not found id:" + id);
|
|
107
|
-
const
|
|
108
|
-
|
|
120
|
+
const index = existing.findIndex((item) => String(item[idKey]) === id);
|
|
121
|
+
if (index === -1) throw new Error("Not found id:" + id);
|
|
122
|
+
existing[index] = {
|
|
123
|
+
...existing[index],
|
|
109
124
|
...data
|
|
110
125
|
};
|
|
111
|
-
|
|
112
|
-
return await this.request(url, {
|
|
126
|
+
await this.request(url, {
|
|
113
127
|
method: "PUT",
|
|
114
|
-
body: JSON.stringify(
|
|
115
|
-
})
|
|
128
|
+
body: JSON.stringify(existing)
|
|
129
|
+
});
|
|
130
|
+
return existing[index];
|
|
116
131
|
}
|
|
117
132
|
/**
|
|
118
133
|
* Delete data
|
|
119
134
|
*/
|
|
120
|
-
async delete(storeName, id,
|
|
121
|
-
const url = this.buildUrl(storeName
|
|
122
|
-
await this.request(url, { method: "
|
|
135
|
+
async delete(storeName, id, idKey = "id") {
|
|
136
|
+
const url = this.buildUrl(storeName);
|
|
137
|
+
const existing = await this.request(url, { method: "GET" });
|
|
138
|
+
if (!existing) throw new Error("Not found id:" + id);
|
|
139
|
+
const index = existing.findIndex((item) => String(item[idKey]) === id);
|
|
140
|
+
if (index === -1) throw new Error("Not found id:" + id);
|
|
141
|
+
existing.splice(index, 1);
|
|
142
|
+
await this.request(url, {
|
|
143
|
+
method: "PUT",
|
|
144
|
+
body: JSON.stringify(existing)
|
|
145
|
+
});
|
|
123
146
|
}
|
|
124
147
|
/**
|
|
125
148
|
* Get data by ID
|
|
126
149
|
*/
|
|
127
|
-
async getData(storeName, id,
|
|
128
|
-
const url = this.buildUrl(storeName
|
|
129
|
-
|
|
150
|
+
async getData(storeName, id, idKey = "id") {
|
|
151
|
+
const url = this.buildUrl(storeName);
|
|
152
|
+
const existing = await this.request(url, { method: "GET" }, { allowNotFound: true });
|
|
153
|
+
if (!existing) return null;
|
|
154
|
+
return existing.find((item) => String(item[idKey]) === id) ?? null;
|
|
130
155
|
}
|
|
131
156
|
/**
|
|
132
157
|
* Get list data (with pagination support)
|
|
133
158
|
*/
|
|
134
159
|
async getList(storeName, options = {}, _idKey = "id") {
|
|
135
|
-
const
|
|
136
|
-
const allData = [];
|
|
137
|
-
for (const file of files) try {
|
|
138
|
-
const data = await this.request(this.buildUrl(storeName, file), { method: "GET" });
|
|
139
|
-
if (data) allData.push(data);
|
|
140
|
-
} catch {}
|
|
160
|
+
const url = this.buildUrl(storeName);
|
|
161
|
+
const allData = await this.request(url, { method: "GET" }, { allowNotFound: true }) || [];
|
|
141
162
|
let filteredData = allData;
|
|
142
163
|
if (options.where) filteredData = allData.filter((item) => {
|
|
143
164
|
for (const key in options.where) if (item[key] !== options.where[key]) return false;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["AdapterType","headers: Record<string, string>","AuthType","allData: T[]","files: string[]"],"sources":["../src/webdav-adapter.ts"],"sourcesContent":["import {\n AdapterType,\n type RemoteAdapter,\n type QueryOptions,\n type PaginatedResult,\n type ServiceConfig,\n AuthType,\n} from \"@omnistreamai/data-core\";\n\n/**\n * WebDAV adapter implementation\n */\nexport class WebDAVAdapter implements RemoteAdapter {\n readonly type = AdapterType.Remote;\n readonly name = \"WebDAVAdapter\";\n\n private service: ServiceConfig | null = null;\n\n /**\n * Set service configuration\n */\n setService(service: ServiceConfig): void {\n this.service = service;\n }\n\n /**\n * Get request headers\n */\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (!this.service?.authentication) {\n return headers;\n }\n\n const { authentication } = this.service;\n\n switch (authentication.authType) {\n case AuthType.Token:\n if (authentication.token) {\n headers[\"Authorization\"] =\n `${authentication.token.token_type} ${authentication.token.access_token}`;\n }\n break;\n case AuthType.Bearer:\n if (authentication.bearer) {\n headers[\"Authorization\"] = `Bearer ${authentication.bearer}`;\n }\n break;\n case AuthType.Basic:\n if (authentication.username && authentication.password) {\n const credentials = btoa(\n `${authentication.username}:${authentication.password}`,\n );\n headers[\"Authorization\"] = `Basic ${credentials}`;\n }\n break;\n }\n\n return headers;\n }\n\n /**\n * Build URL\n */\n private buildUrl(storeName: string, id?: string): string {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const storePath = `/${storeName}`;\n\n if (id) {\n return `${baseUrl}${storePath}/${id}`;\n }\n\n return `${baseUrl}${storePath}`;\n }\n\n /**\n * Send request\n */\n private async request<T>(\n url: string,\n options: RequestInit = {},\n {\n allowNotFound,\n }: {\n allowNotFound?: boolean;\n } = {},\n ): Promise<T | null> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.getHeaders(),\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n if (allowNotFound && response.status == 404) {\n return null;\n }\n throw new Error(\n `HTTP error! status: ${response.status}, message: ${response.statusText}`,\n );\n }\n\n const text = await response.text();\n if (!text) {\n return null;\n }\n\n try {\n return JSON.parse(text) as T;\n } catch {\n return null;\n }\n }\n\n /**\n * Initialize store\n */\n async initStore(\n storeName: string,\n _indexes: string[] = [],\n _idKey: string = \"id\",\n ): Promise<void> {\n const path = storeName.replace(/^\\/+|\\/+$/g, \"\");\n const parts = path.split(\"/\");\n\n let currentPath = \"\";\n for (const part of parts) {\n currentPath = currentPath ? `${currentPath}/${part}` : part;\n\n try {\n await this.listDirectory(currentPath);\n } catch {\n const url = this.buildUrl(currentPath);\n\n const response = await fetch(url, {\n method: \"MKCOL\",\n headers: this.getHeaders(),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create store: ${response.statusText}`);\n }\n }\n }\n }\n\n /**\n * Add data\n */\n async add<T extends Record<string, unknown>>(\n storeName: string,\n data: T,\n idKey: string = \"id\",\n ): Promise<T> {\n const id = String(data[idKey]);\n const url = this.buildUrl(storeName, id);\n\n const result = await this.request<T>(url, {\n method: \"PUT\",\n body: JSON.stringify(data),\n });\n\n return result ?? data;\n }\n\n /**\n * Update data\n */\n async update<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n data: Partial<T>,\n idKey: string = \"id\",\n ): Promise<T> {\n const existing = await this.getData<T>(storeName, id, idKey);\n if (!existing) {\n throw new Error(\"Not found id:\" + id);\n }\n\n const updated = { ...existing, ...data };\n const url = this.buildUrl(storeName, id);\n\n const result = await this.request<T>(url, {\n method: \"PUT\",\n body: JSON.stringify(updated),\n });\n\n return result ?? updated;\n }\n\n /**\n * Delete data\n */\n async delete(\n storeName: string,\n id: string,\n _idKey: string = \"id\",\n ): Promise<void> {\n const url = this.buildUrl(storeName, id);\n\n await this.request(url, {\n method: \"DELETE\",\n });\n }\n\n /**\n * Get data by ID\n */\n async getData<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n _idKey: string = \"id\",\n ): Promise<T | null> {\n const url = this.buildUrl(storeName, id);\n\n const result = await this.request<T>(\n url,\n {\n method: \"GET\",\n },\n {\n allowNotFound: true,\n },\n );\n\n return result;\n }\n\n /**\n * Get list data (with pagination support)\n */\n async getList<T extends Record<string, unknown>>(\n storeName: string,\n options: QueryOptions<T> = {},\n _idKey: string = \"id\",\n ): Promise<PaginatedResult<T>> {\n const files = await this.listDirectory(storeName);\n\n const allData: T[] = [];\n for (const file of files) {\n try {\n const data = await this.request<T>(this.buildUrl(storeName, file), {\n method: \"GET\",\n });\n if (data) {\n allData.push(data);\n }\n } catch {}\n }\n\n let filteredData = allData;\n\n if (options.where) {\n filteredData = allData.filter((item) => {\n for (const key in options.where) {\n const itemValue = item[key];\n const whereValue = options.where![key];\n if (itemValue !== whereValue) {\n return false;\n }\n }\n return true;\n });\n }\n\n // Sorting\n if (options.sortBy) {\n filteredData = this.sortEntries(\n filteredData,\n String(options.sortBy),\n options.sortOrder,\n );\n }\n\n const totalCount = filteredData.length;\n const page = options.page ?? 1;\n const limit = options.limit ?? totalCount;\n\n const startIndex = (page - 1) * limit;\n const endIndex = startIndex + limit;\n const paginatedData = filteredData.slice(startIndex, endIndex);\n\n return {\n data: paginatedData,\n totalCount,\n page,\n limit,\n };\n }\n\n /**\n * Sort entries by specified field\n * @param entries Array of entries to sort\n * @param key Sorting field name\n * @param sortOrder Sort order: 'asc' or 'desc' (default: 'asc')\n * @returns Sorted array of entries\n */\n private sortEntries<T extends Record<string, unknown>>(\n entries: T[],\n key: string,\n sortOrder: \"asc\" | \"desc\" = \"asc\",\n ): T[] {\n return [...entries].sort((a, b) => {\n const aValue = a[key];\n const bValue = b[key];\n\n // Handle undefined or null values\n if (aValue == null && bValue == null) return 0;\n if (aValue == null) return 1; // null/undefined at the end\n if (bValue == null) return -1; // null/undefined at the end\n\n let comparison = 0;\n\n // Number type sorting\n if (typeof aValue === \"number\" && typeof bValue === \"number\") {\n comparison = aValue - bValue;\n }\n // String type sorting\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n comparison = aValue.localeCompare(bValue);\n }\n // Date type sorting (if string format date)\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n const aDate = new Date(aValue);\n const bDate = new Date(bValue);\n if (!isNaN(aDate.getTime()) && !isNaN(bDate.getTime())) {\n comparison = aDate.getTime() - bDate.getTime();\n } else {\n // Convert other types to string for comparison\n comparison = String(aValue).localeCompare(String(bValue));\n }\n }\n // Convert other types to string for comparison\n else {\n comparison = String(aValue).localeCompare(String(bValue));\n }\n\n // Apply sort order\n return sortOrder === \"desc\" ? -comparison : comparison;\n });\n }\n\n /**\n * Clear store\n */\n async clear(storeName: string): Promise<void> {\n const list = await this.getList(storeName);\n\n for (const item of list.data) {\n const id = String((item as Record<string, unknown>)[\"id\"]);\n await this.delete(storeName, id);\n }\n }\n\n /**\n * List directory contents\n */\n async listDirectory(path: string = \"\"): Promise<string[]> {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const url = path ? `${baseUrl}/${path.replace(/^\\//, \"\")}` : baseUrl;\n\n const response = await fetch(url, {\n method: \"PROPFIND\",\n headers: {\n ...this.getHeaders(),\n Depth: \"1\",\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to list directory: ${response.statusText}`);\n }\n\n const text = await response.text();\n\n const hrefRegex = /<d:href[^>]*>([^<]+)<\\/d:href>/gi;\n const files: string[] = [];\n let match;\n\n const baseUrlObj = new URL(baseUrl);\n const basePath = baseUrlObj.pathname;\n\n while ((match = hrefRegex.exec(text)) !== null) {\n const fullPath = match[1] || \"\";\n let relativePath = \"\";\n try {\n const hrefUrl = new URL(fullPath);\n relativePath = hrefUrl.pathname;\n } catch {}\n const pathRegex = new RegExp(`^/*${path}`)\n relativePath = fullPath.replace(basePath, \"\").replace(pathRegex, '').replace(/^\\//, \"\");\n if (relativePath && relativePath !== path.replace(/^\\//, \"\")) {\n files.push(relativePath);\n }\n }\n\n return files;\n }\n\n /**\n * Test connection\n */\n async testConnection(): Promise<boolean> {\n try {\n await this.listDirectory(\"\");\n return true;\n } catch {\n return false;\n }\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,gBAAb,MAAoD;CAClD,AAAS,OAAOA,qCAAY;CAC5B,AAAS,OAAO;CAEhB,AAAQ,UAAgC;;;;CAKxC,WAAW,SAA8B;AACvC,OAAK,UAAU;;;;;CAMjB,AAAQ,aAAqC;EAC3C,MAAMC,UAAkC,EACtC,gBAAgB,oBACjB;AAED,MAAI,CAAC,KAAK,SAAS,eACjB,QAAO;EAGT,MAAM,EAAE,mBAAmB,KAAK;AAEhC,UAAQ,eAAe,UAAvB;GACE,KAAKC,kCAAS;AACZ,QAAI,eAAe,MACjB,SAAQ,mBACN,GAAG,eAAe,MAAM,WAAW,GAAG,eAAe,MAAM;AAE/D;GACF,KAAKA,kCAAS;AACZ,QAAI,eAAe,OACjB,SAAQ,mBAAmB,UAAU,eAAe;AAEtD;GACF,KAAKA,kCAAS;AACZ,QAAI,eAAe,YAAY,eAAe,SAI5C,SAAQ,mBAAmB,SAHP,KAClB,GAAG,eAAe,SAAS,GAAG,eAAe,WAC9C;AAGH;;AAGJ,SAAO;;;;;CAMT,AAAQ,SAAS,WAAmB,IAAqB;AACvD,MAAI,CAAC,KAAK,QACR,OAAM,IAAI,MAAM,mDAAmD;EAGrE,MAAM,UAAU,KAAK,QAAQ,SAAS,QAAQ,OAAO,GAAG;EACxD,MAAM,YAAY,IAAI;AAEtB,MAAI,GACF,QAAO,GAAG,UAAU,UAAU,GAAG;AAGnC,SAAO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,SAAS,QAAQ,OAAO,GAAG;EACxD,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,KAAK,QAAQ,OAAO,GAAG,KAAK;EAE7D,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,QAAQ;GACR,SAAS;IACP,GAAG,KAAK,YAAY;IACpB,OAAO;IACR;GACF,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,6BAA6B,SAAS,aAAa;EAGrE,MAAM,OAAO,MAAM,SAAS,MAAM;EAElC,MAAM,YAAY;EAClB,MAAMC,QAAkB,EAAE;EAC1B,IAAI;EAGJ,MAAM,WADa,IAAI,IAAI,QAAQ,CACP;AAE5B,UAAQ,QAAQ,UAAU,KAAK,KAAK,MAAM,MAAM;GAC9C,MAAM,WAAW,MAAM,MAAM;GAC7B,IAAI,eAAe;AACnB,OAAI;AAEF,mBADgB,IAAI,IAAI,SAAS,CACV;WACjB;GACR,MAAM,4BAAY,IAAI,OAAO,MAAM,OAAO;AAC1C,kBAAe,SAAS,QAAQ,UAAU,GAAG,CAAC,QAAQ,WAAW,GAAG,CAAC,QAAQ,OAAO,GAAG;AACvF,OAAI,gBAAgB,iBAAiB,KAAK,QAAQ,OAAO,GAAG,CAC1D,OAAM,KAAK,aAAa;;AAI5B,SAAO;;;;;CAMT,MAAM,iBAAmC;AACvC,MAAI;AACF,SAAM,KAAK,cAAc,GAAG;AAC5B,UAAO;UACD;AACN,UAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["AdapterType","headers: Record<string, string>","AuthType","files: string[]"],"sources":["../src/webdav-adapter.ts"],"sourcesContent":["import {\n AdapterType,\n type RemoteAdapter,\n type QueryOptions,\n type PaginatedResult,\n type ServiceConfig,\n AuthType,\n} from \"@omnistreamai/data-core\";\n\n/**\n * WebDAV adapter implementation\n */\nexport class WebDAVAdapter implements RemoteAdapter {\n readonly type = AdapterType.Remote;\n readonly name = \"WebDAVAdapter\";\n\n private service: ServiceConfig | null = null;\n\n /**\n * Set service configuration\n */\n setService(service: ServiceConfig): void {\n this.service = service;\n }\n\n /**\n * Get request headers\n */\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (!this.service?.authentication) {\n return headers;\n }\n\n const { authentication } = this.service;\n\n switch (authentication.authType) {\n case AuthType.Token:\n if (authentication.token) {\n headers[\"Authorization\"] =\n `${authentication.token.token_type} ${authentication.token.access_token}`;\n }\n break;\n case AuthType.Bearer:\n if (authentication.bearer) {\n headers[\"Authorization\"] = `Bearer ${authentication.bearer}`;\n }\n break;\n case AuthType.Basic:\n if (authentication.username && authentication.password) {\n const credentials = btoa(\n `${authentication.username}:${authentication.password}`,\n );\n headers[\"Authorization\"] = `Basic ${credentials}`;\n }\n break;\n }\n\n return headers;\n }\n\n /**\n * Build URL\n */\n private buildUrl(storeName: string): string {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const basePath = this.service.basePath ? `/${this.service.basePath.replace(/^\\/+|\\/+$/g, \"\")}` : \"\";\n return `${baseUrl}${basePath}/${storeName}.json`;\n }\n\n /**\n * Send request\n */\n private async request<T>(\n url: string,\n options: RequestInit = {},\n {\n allowNotFound,\n }: {\n allowNotFound?: boolean;\n } = {},\n ): Promise<T | null> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.getHeaders(),\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n if (allowNotFound && response.status == 404) {\n return null;\n }\n throw new Error(\n `HTTP error! status: ${response.status}, message: ${response.statusText}`,\n );\n }\n\n const text = await response.text();\n if (!text) {\n return null;\n }\n\n try {\n return JSON.parse(text) as T;\n } catch {\n return null;\n }\n }\n\n /**\n * Initialize store\n */\n async initStore(\n storeName: string,\n _indexes: string[] = [],\n _idKey: string = \"id\",\n ): Promise<void> {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n if (this.service.basePath) {\n const basePath = this.service.basePath.replace(/^\\/+|\\/+$/g, \"\");\n const parts = basePath.split(\"/\");\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n\n let currentPath = \"\";\n for (const part of parts) {\n currentPath = currentPath ? `${currentPath}/${part}` : part;\n\n try {\n await this.listDirectory(currentPath);\n } catch {\n const url = `${baseUrl}/${currentPath}`;\n\n const response = await fetch(url, {\n method: \"MKCOL\",\n headers: this.getHeaders(),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create base path: ${response.statusText}`);\n }\n }\n }\n }\n\n const jsonFileUrl = this.buildUrl(storeName);\n const result = await this.request<unknown[]>(jsonFileUrl, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n });\n\n if (!result) {\n const response = await fetch(jsonFileUrl, {\n method: \"PUT\",\n headers: this.getHeaders(),\n body: JSON.stringify([]),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create JSON file: ${response.statusText}`);\n }\n }\n }\n\n /**\n * Add data\n */\n async add<T extends Record<string, unknown>>(\n storeName: string,\n data: T,\n _idKey: string = \"id\",\n ): Promise<T> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<T[]>(url, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n });\n\n const items = existing || [];\n items.push(data);\n\n await this.request(url, {\n method: \"PUT\",\n body: JSON.stringify(items),\n });\n\n return data;\n }\n\n /**\n * Update data\n */\n async update<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n data: Partial<T>,\n idKey: string = \"id\",\n ): Promise<T> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<T[]>(url, {\n method: \"GET\",\n });\n\n if (!existing) {\n throw new Error(\"Not found id:\" + id);\n }\n\n const index = existing.findIndex(item => String(item[idKey]) === id);\n if (index === -1) {\n throw new Error(\"Not found id:\" + id);\n }\n\n existing[index] = { ...existing[index], ...data } as T;\n\n await this.request(url, {\n method: \"PUT\",\n body: JSON.stringify(existing),\n });\n\n return existing[index];\n }\n\n /**\n * Delete data\n */\n async delete(\n storeName: string,\n id: string,\n idKey: string = \"id\",\n ): Promise<void> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<Record<string, unknown>[]>(url, {\n method: \"GET\",\n });\n\n if (!existing) {\n throw new Error(\"Not found id:\" + id);\n }\n\n const index = existing.findIndex(item => String(item[idKey]) === id);\n if (index === -1) {\n throw new Error(\"Not found id:\" + id);\n }\n\n existing.splice(index, 1);\n\n await this.request(url, {\n method: \"PUT\",\n body: JSON.stringify(existing),\n });\n }\n\n /**\n * Get data by ID\n */\n async getData<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n idKey: string = \"id\",\n ): Promise<T | null> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<T[]>(url, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n });\n\n if (!existing) {\n return null;\n }\n\n const item = existing.find(item => String(item[idKey]) === id);\n return item ?? null;\n }\n\n /**\n * Get list data (with pagination support)\n */\n async getList<T extends Record<string, unknown>>(\n storeName: string,\n options: QueryOptions<T> = {},\n _idKey: string = \"id\",\n ): Promise<PaginatedResult<T>> {\n const url = this.buildUrl(storeName);\n\n const allData = await this.request<T[]>(url, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n }) || [];\n\n let filteredData = allData;\n\n if (options.where) {\n filteredData = allData.filter((item) => {\n for (const key in options.where) {\n const itemValue = item[key];\n const whereValue = options.where![key];\n if (itemValue !== whereValue) {\n return false;\n }\n }\n return true;\n });\n }\n\n // Sorting\n if (options.sortBy) {\n filteredData = this.sortEntries(\n filteredData,\n String(options.sortBy),\n options.sortOrder,\n );\n }\n\n const totalCount = filteredData.length;\n const page = options.page ?? 1;\n const limit = options.limit ?? totalCount;\n\n const startIndex = (page - 1) * limit;\n const endIndex = startIndex + limit;\n const paginatedData = filteredData.slice(startIndex, endIndex);\n\n return {\n data: paginatedData,\n totalCount,\n page,\n limit,\n };\n }\n\n /**\n * Sort entries by specified field\n * @param entries Array of entries to sort\n * @param key Sorting field name\n * @param sortOrder Sort order: 'asc' or 'desc' (default: 'asc')\n * @returns Sorted array of entries\n */\n private sortEntries<T extends Record<string, unknown>>(\n entries: T[],\n key: string,\n sortOrder: \"asc\" | \"desc\" = \"asc\",\n ): T[] {\n return [...entries].sort((a, b) => {\n const aValue = a[key];\n const bValue = b[key];\n\n // Handle undefined or null values\n if (aValue == null && bValue == null) return 0;\n if (aValue == null) return 1; // null/undefined at the end\n if (bValue == null) return -1; // null/undefined at the end\n\n let comparison = 0;\n\n // Number type sorting\n if (typeof aValue === \"number\" && typeof bValue === \"number\") {\n comparison = aValue - bValue;\n }\n // String type sorting\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n comparison = aValue.localeCompare(bValue);\n }\n // Date type sorting (if string format date)\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n const aDate = new Date(aValue);\n const bDate = new Date(bValue);\n if (!isNaN(aDate.getTime()) && !isNaN(bDate.getTime())) {\n comparison = aDate.getTime() - bDate.getTime();\n } else {\n // Convert other types to string for comparison\n comparison = String(aValue).localeCompare(String(bValue));\n }\n }\n // Convert other types to string for comparison\n else {\n comparison = String(aValue).localeCompare(String(bValue));\n }\n\n // Apply sort order\n return sortOrder === \"desc\" ? -comparison : comparison;\n });\n }\n\n /**\n * Clear store\n */\n async clear(storeName: string): Promise<void> {\n const list = await this.getList(storeName);\n\n for (const item of list.data) {\n const id = String((item as Record<string, unknown>)[\"id\"]);\n await this.delete(storeName, id);\n }\n }\n\n /**\n * List directory contents\n */\n async listDirectory(path: string = \"\"): Promise<string[]> {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const url = path ? `${baseUrl}/${path.replace(/^\\//, \"\")}` : baseUrl;\n\n const response = await fetch(url, {\n method: \"PROPFIND\",\n headers: {\n ...this.getHeaders(),\n Depth: \"1\",\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to list directory: ${response.statusText}`);\n }\n\n const text = await response.text();\n\n const hrefRegex = /<d:href[^>]*>([^<]+)<\\/d:href>/gi;\n const files: string[] = [];\n let match;\n\n const baseUrlObj = new URL(baseUrl);\n const basePath = baseUrlObj.pathname;\n\n while ((match = hrefRegex.exec(text)) !== null) {\n const fullPath = match[1] || \"\";\n let relativePath = \"\";\n try {\n const hrefUrl = new URL(fullPath);\n relativePath = hrefUrl.pathname;\n } catch {}\n const pathRegex = new RegExp(`^/*${path}`)\n relativePath = fullPath.replace(basePath, \"\").replace(pathRegex, '').replace(/^\\//, \"\");\n if (relativePath && relativePath !== path.replace(/^\\//, \"\")) {\n files.push(relativePath);\n }\n }\n\n return files;\n }\n\n /**\n * Test connection\n */\n async testConnection(): Promise<boolean> {\n try {\n await this.listDirectory(\"\");\n return true;\n } catch {\n return false;\n }\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,gBAAb,MAAoD;CAClD,AAAS,OAAOA,qCAAY;CAC5B,AAAS,OAAO;CAEhB,AAAQ,UAAgC;;;;CAKxC,WAAW,SAA8B;AACvC,OAAK,UAAU;;;;;CAMjB,AAAQ,aAAqC;EAC3C,MAAMC,UAAkC,EACtC,gBAAgB,oBACjB;AAED,MAAI,CAAC,KAAK,SAAS,eACjB,QAAO;EAGT,MAAM,EAAE,mBAAmB,KAAK;AAEhC,UAAQ,eAAe,UAAvB;GACE,KAAKC,kCAAS;AACZ,QAAI,eAAe,MACjB,SAAQ,mBACN,GAAG,eAAe,MAAM,WAAW,GAAG,eAAe,MAAM;AAE/D;GACF,KAAKA,kCAAS;AACZ,QAAI,eAAe,OACjB,SAAQ,mBAAmB,UAAU,eAAe;AAEtD;GACF,KAAKA,kCAAS;AACZ,QAAI,eAAe,YAAY,eAAe,SAI5C,SAAQ,mBAAmB,SAHP,KAClB,GAAG,eAAe,SAAS,GAAG,eAAe,WAC9C;AAGH;;AAGJ,SAAO;;;;;CAMT,AAAQ,SAAS,WAA2B;AAC1C,MAAI,CAAC,KAAK,QACR,OAAM,IAAI,MAAM,mDAAm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,GAAG,KAAK,QAAQ,OAAO,GAAG,KAAK;EAE7D,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,QAAQ;GACR,SAAS;IACP,GAAG,KAAK,YAAY;IACpB,OAAO;IACR;GACF,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,6BAA6B,SAAS,aAAa;EAGrE,MAAM,OAAO,MAAM,SAAS,MAAM;EAElC,MAAM,YAAY;EAClB,MAAMC,QAAkB,EAAE;EAC1B,IAAI;EAGJ,MAAM,WADa,IAAI,IAAI,QAAQ,CACP;AAE5B,UAAQ,QAAQ,UAAU,KAAK,KAAK,MAAM,MAAM;GAC9C,MAAM,WAAW,MAAM,MAAM;GAC7B,IAAI,eAAe;AACnB,OAAI;AAEF,mBADgB,IAAI,IAAI,SAAS,CACV;WACjB;GACR,MAAM,4BAAY,IAAI,OAAO,MAAM,OAAO;AAC1C,kBAAe,SAAS,QAAQ,UAAU,GAAG,CAAC,QAAQ,WAAW,GAAG,CAAC,QAAQ,OAAO,GAAG;AACvF,OAAI,gBAAgB,iBAAiB,KAAK,QAAQ,OAAO,GAAG,CAC1D,OAAM,KAAK,aAAa;;AAI5B,SAAO;;;;;CAMT,MAAM,iBAAmC;AACvC,MAAI;AACF,SAAM,KAAK,cAAc,GAAG;AAC5B,UAAO;UACD;AACN,UAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -37,12 +37,9 @@ var WebDAVAdapter = class {
|
|
|
37
37
|
/**
|
|
38
38
|
* Build URL
|
|
39
39
|
*/
|
|
40
|
-
buildUrl(storeName
|
|
40
|
+
buildUrl(storeName) {
|
|
41
41
|
if (!this.service) throw new Error("Service not configured. Call setService() first.");
|
|
42
|
-
|
|
43
|
-
const storePath = `/${storeName}`;
|
|
44
|
-
if (id) return `${baseUrl}${storePath}/${id}`;
|
|
45
|
-
return `${baseUrl}${storePath}`;
|
|
42
|
+
return `${this.service.endpoint.replace(/\/$/, "")}${this.service.basePath ? `/${this.service.basePath.replace(/^\/+|\/+$/g, "")}` : ""}/${storeName}.json`;
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
45
|
* Send request
|
|
@@ -71,73 +68,97 @@ var WebDAVAdapter = class {
|
|
|
71
68
|
* Initialize store
|
|
72
69
|
*/
|
|
73
70
|
async initStore(storeName, _indexes = [], _idKey = "id") {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
if (!this.service) throw new Error("Service not configured. Call setService() first.");
|
|
72
|
+
if (this.service.basePath) {
|
|
73
|
+
const parts = this.service.basePath.replace(/^\/+|\/+$/g, "").split("/");
|
|
74
|
+
const baseUrl = this.service.endpoint.replace(/\/$/, "");
|
|
75
|
+
let currentPath = "";
|
|
76
|
+
for (const part of parts) {
|
|
77
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
78
|
+
try {
|
|
79
|
+
await this.listDirectory(currentPath);
|
|
80
|
+
} catch {
|
|
81
|
+
const url = `${baseUrl}/${currentPath}`;
|
|
82
|
+
const response = await fetch(url, {
|
|
83
|
+
method: "MKCOL",
|
|
84
|
+
headers: this.getHeaders()
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) throw new Error(`Failed to create base path: ${response.statusText}`);
|
|
87
|
+
}
|
|
87
88
|
}
|
|
88
89
|
}
|
|
90
|
+
const jsonFileUrl = this.buildUrl(storeName);
|
|
91
|
+
if (!await this.request(jsonFileUrl, { method: "GET" }, { allowNotFound: true })) {
|
|
92
|
+
const response = await fetch(jsonFileUrl, {
|
|
93
|
+
method: "PUT",
|
|
94
|
+
headers: this.getHeaders(),
|
|
95
|
+
body: JSON.stringify([])
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok) throw new Error(`Failed to create JSON file: ${response.statusText}`);
|
|
98
|
+
}
|
|
89
99
|
}
|
|
90
100
|
/**
|
|
91
101
|
* Add data
|
|
92
102
|
*/
|
|
93
|
-
async add(storeName, data,
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
103
|
+
async add(storeName, data, _idKey = "id") {
|
|
104
|
+
const url = this.buildUrl(storeName);
|
|
105
|
+
const items = await this.request(url, { method: "GET" }, { allowNotFound: true }) || [];
|
|
106
|
+
items.push(data);
|
|
107
|
+
await this.request(url, {
|
|
97
108
|
method: "PUT",
|
|
98
|
-
body: JSON.stringify(
|
|
99
|
-
})
|
|
109
|
+
body: JSON.stringify(items)
|
|
110
|
+
});
|
|
111
|
+
return data;
|
|
100
112
|
}
|
|
101
113
|
/**
|
|
102
114
|
* Update data
|
|
103
115
|
*/
|
|
104
116
|
async update(storeName, id, data, idKey = "id") {
|
|
105
|
-
const
|
|
117
|
+
const url = this.buildUrl(storeName);
|
|
118
|
+
const existing = await this.request(url, { method: "GET" });
|
|
106
119
|
if (!existing) throw new Error("Not found id:" + id);
|
|
107
|
-
const
|
|
108
|
-
|
|
120
|
+
const index = existing.findIndex((item) => String(item[idKey]) === id);
|
|
121
|
+
if (index === -1) throw new Error("Not found id:" + id);
|
|
122
|
+
existing[index] = {
|
|
123
|
+
...existing[index],
|
|
109
124
|
...data
|
|
110
125
|
};
|
|
111
|
-
|
|
112
|
-
return await this.request(url, {
|
|
126
|
+
await this.request(url, {
|
|
113
127
|
method: "PUT",
|
|
114
|
-
body: JSON.stringify(
|
|
115
|
-
})
|
|
128
|
+
body: JSON.stringify(existing)
|
|
129
|
+
});
|
|
130
|
+
return existing[index];
|
|
116
131
|
}
|
|
117
132
|
/**
|
|
118
133
|
* Delete data
|
|
119
134
|
*/
|
|
120
|
-
async delete(storeName, id,
|
|
121
|
-
const url = this.buildUrl(storeName
|
|
122
|
-
await this.request(url, { method: "
|
|
135
|
+
async delete(storeName, id, idKey = "id") {
|
|
136
|
+
const url = this.buildUrl(storeName);
|
|
137
|
+
const existing = await this.request(url, { method: "GET" });
|
|
138
|
+
if (!existing) throw new Error("Not found id:" + id);
|
|
139
|
+
const index = existing.findIndex((item) => String(item[idKey]) === id);
|
|
140
|
+
if (index === -1) throw new Error("Not found id:" + id);
|
|
141
|
+
existing.splice(index, 1);
|
|
142
|
+
await this.request(url, {
|
|
143
|
+
method: "PUT",
|
|
144
|
+
body: JSON.stringify(existing)
|
|
145
|
+
});
|
|
123
146
|
}
|
|
124
147
|
/**
|
|
125
148
|
* Get data by ID
|
|
126
149
|
*/
|
|
127
|
-
async getData(storeName, id,
|
|
128
|
-
const url = this.buildUrl(storeName
|
|
129
|
-
|
|
150
|
+
async getData(storeName, id, idKey = "id") {
|
|
151
|
+
const url = this.buildUrl(storeName);
|
|
152
|
+
const existing = await this.request(url, { method: "GET" }, { allowNotFound: true });
|
|
153
|
+
if (!existing) return null;
|
|
154
|
+
return existing.find((item) => String(item[idKey]) === id) ?? null;
|
|
130
155
|
}
|
|
131
156
|
/**
|
|
132
157
|
* Get list data (with pagination support)
|
|
133
158
|
*/
|
|
134
159
|
async getList(storeName, options = {}, _idKey = "id") {
|
|
135
|
-
const
|
|
136
|
-
const allData = [];
|
|
137
|
-
for (const file of files) try {
|
|
138
|
-
const data = await this.request(this.buildUrl(storeName, file), { method: "GET" });
|
|
139
|
-
if (data) allData.push(data);
|
|
140
|
-
} catch {}
|
|
160
|
+
const url = this.buildUrl(storeName);
|
|
161
|
+
const allData = await this.request(url, { method: "GET" }, { allowNotFound: true }) || [];
|
|
141
162
|
let filteredData = allData;
|
|
142
163
|
if (options.where) filteredData = allData.filter((item) => {
|
|
143
164
|
for (const key in options.where) if (item[key] !== options.where[key]) return false;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["headers: Record<string, string>","allData: T[]","files: string[]"],"sources":["../src/webdav-adapter.ts"],"sourcesContent":["import {\n AdapterType,\n type RemoteAdapter,\n type QueryOptions,\n type PaginatedResult,\n type ServiceConfig,\n AuthType,\n} from \"@omnistreamai/data-core\";\n\n/**\n * WebDAV adapter implementation\n */\nexport class WebDAVAdapter implements RemoteAdapter {\n readonly type = AdapterType.Remote;\n readonly name = \"WebDAVAdapter\";\n\n private service: ServiceConfig | null = null;\n\n /**\n * Set service configuration\n */\n setService(service: ServiceConfig): void {\n this.service = service;\n }\n\n /**\n * Get request headers\n */\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (!this.service?.authentication) {\n return headers;\n }\n\n const { authentication } = this.service;\n\n switch (authentication.authType) {\n case AuthType.Token:\n if (authentication.token) {\n headers[\"Authorization\"] =\n `${authentication.token.token_type} ${authentication.token.access_token}`;\n }\n break;\n case AuthType.Bearer:\n if (authentication.bearer) {\n headers[\"Authorization\"] = `Bearer ${authentication.bearer}`;\n }\n break;\n case AuthType.Basic:\n if (authentication.username && authentication.password) {\n const credentials = btoa(\n `${authentication.username}:${authentication.password}`,\n );\n headers[\"Authorization\"] = `Basic ${credentials}`;\n }\n break;\n }\n\n return headers;\n }\n\n /**\n * Build URL\n */\n private buildUrl(storeName: string, id?: string): string {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const storePath = `/${storeName}`;\n\n if (id) {\n return `${baseUrl}${storePath}/${id}`;\n }\n\n return `${baseUrl}${storePath}`;\n }\n\n /**\n * Send request\n */\n private async request<T>(\n url: string,\n options: RequestInit = {},\n {\n allowNotFound,\n }: {\n allowNotFound?: boolean;\n } = {},\n ): Promise<T | null> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.getHeaders(),\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n if (allowNotFound && response.status == 404) {\n return null;\n }\n throw new Error(\n `HTTP error! status: ${response.status}, message: ${response.statusText}`,\n );\n }\n\n const text = await response.text();\n if (!text) {\n return null;\n }\n\n try {\n return JSON.parse(text) as T;\n } catch {\n return null;\n }\n }\n\n /**\n * Initialize store\n */\n async initStore(\n storeName: string,\n _indexes: string[] = [],\n _idKey: string = \"id\",\n ): Promise<void> {\n const path = storeName.replace(/^\\/+|\\/+$/g, \"\");\n const parts = path.split(\"/\");\n\n let currentPath = \"\";\n for (const part of parts) {\n currentPath = currentPath ? `${currentPath}/${part}` : part;\n\n try {\n await this.listDirectory(currentPath);\n } catch {\n const url = this.buildUrl(currentPath);\n\n const response = await fetch(url, {\n method: \"MKCOL\",\n headers: this.getHeaders(),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create store: ${response.statusText}`);\n }\n }\n }\n }\n\n /**\n * Add data\n */\n async add<T extends Record<string, unknown>>(\n storeName: string,\n data: T,\n idKey: string = \"id\",\n ): Promise<T> {\n const id = String(data[idKey]);\n const url = this.buildUrl(storeName, id);\n\n const result = await this.request<T>(url, {\n method: \"PUT\",\n body: JSON.stringify(data),\n });\n\n return result ?? data;\n }\n\n /**\n * Update data\n */\n async update<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n data: Partial<T>,\n idKey: string = \"id\",\n ): Promise<T> {\n const existing = await this.getData<T>(storeName, id, idKey);\n if (!existing) {\n throw new Error(\"Not found id:\" + id);\n }\n\n const updated = { ...existing, ...data };\n const url = this.buildUrl(storeName, id);\n\n const result = await this.request<T>(url, {\n method: \"PUT\",\n body: JSON.stringify(updated),\n });\n\n return result ?? updated;\n }\n\n /**\n * Delete data\n */\n async delete(\n storeName: string,\n id: string,\n _idKey: string = \"id\",\n ): Promise<void> {\n const url = this.buildUrl(storeName, id);\n\n await this.request(url, {\n method: \"DELETE\",\n });\n }\n\n /**\n * Get data by ID\n */\n async getData<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n _idKey: string = \"id\",\n ): Promise<T | null> {\n const url = this.buildUrl(storeName, id);\n\n const result = await this.request<T>(\n url,\n {\n method: \"GET\",\n },\n {\n allowNotFound: true,\n },\n );\n\n return result;\n }\n\n /**\n * Get list data (with pagination support)\n */\n async getList<T extends Record<string, unknown>>(\n storeName: string,\n options: QueryOptions<T> = {},\n _idKey: string = \"id\",\n ): Promise<PaginatedResult<T>> {\n const files = await this.listDirectory(storeName);\n\n const allData: T[] = [];\n for (const file of files) {\n try {\n const data = await this.request<T>(this.buildUrl(storeName, file), {\n method: \"GET\",\n });\n if (data) {\n allData.push(data);\n }\n } catch {}\n }\n\n let filteredData = allData;\n\n if (options.where) {\n filteredData = allData.filter((item) => {\n for (const key in options.where) {\n const itemValue = item[key];\n const whereValue = options.where![key];\n if (itemValue !== whereValue) {\n return false;\n }\n }\n return true;\n });\n }\n\n // Sorting\n if (options.sortBy) {\n filteredData = this.sortEntries(\n filteredData,\n String(options.sortBy),\n options.sortOrder,\n );\n }\n\n const totalCount = filteredData.length;\n const page = options.page ?? 1;\n const limit = options.limit ?? totalCount;\n\n const startIndex = (page - 1) * limit;\n const endIndex = startIndex + limit;\n const paginatedData = filteredData.slice(startIndex, endIndex);\n\n return {\n data: paginatedData,\n totalCount,\n page,\n limit,\n };\n }\n\n /**\n * Sort entries by specified field\n * @param entries Array of entries to sort\n * @param key Sorting field name\n * @param sortOrder Sort order: 'asc' or 'desc' (default: 'asc')\n * @returns Sorted array of entries\n */\n private sortEntries<T extends Record<string, unknown>>(\n entries: T[],\n key: string,\n sortOrder: \"asc\" | \"desc\" = \"asc\",\n ): T[] {\n return [...entries].sort((a, b) => {\n const aValue = a[key];\n const bValue = b[key];\n\n // Handle undefined or null values\n if (aValue == null && bValue == null) return 0;\n if (aValue == null) return 1; // null/undefined at the end\n if (bValue == null) return -1; // null/undefined at the end\n\n let comparison = 0;\n\n // Number type sorting\n if (typeof aValue === \"number\" && typeof bValue === \"number\") {\n comparison = aValue - bValue;\n }\n // String type sorting\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n comparison = aValue.localeCompare(bValue);\n }\n // Date type sorting (if string format date)\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n const aDate = new Date(aValue);\n const bDate = new Date(bValue);\n if (!isNaN(aDate.getTime()) && !isNaN(bDate.getTime())) {\n comparison = aDate.getTime() - bDate.getTime();\n } else {\n // Convert other types to string for comparison\n comparison = String(aValue).localeCompare(String(bValue));\n }\n }\n // Convert other types to string for comparison\n else {\n comparison = String(aValue).localeCompare(String(bValue));\n }\n\n // Apply sort order\n return sortOrder === \"desc\" ? -comparison : comparison;\n });\n }\n\n /**\n * Clear store\n */\n async clear(storeName: string): Promise<void> {\n const list = await this.getList(storeName);\n\n for (const item of list.data) {\n const id = String((item as Record<string, unknown>)[\"id\"]);\n await this.delete(storeName, id);\n }\n }\n\n /**\n * List directory contents\n */\n async listDirectory(path: string = \"\"): Promise<string[]> {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const url = path ? `${baseUrl}/${path.replace(/^\\//, \"\")}` : baseUrl;\n\n const response = await fetch(url, {\n method: \"PROPFIND\",\n headers: {\n ...this.getHeaders(),\n Depth: \"1\",\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to list directory: ${response.statusText}`);\n }\n\n const text = await response.text();\n\n const hrefRegex = /<d:href[^>]*>([^<]+)<\\/d:href>/gi;\n const files: string[] = [];\n let match;\n\n const baseUrlObj = new URL(baseUrl);\n const basePath = baseUrlObj.pathname;\n\n while ((match = hrefRegex.exec(text)) !== null) {\n const fullPath = match[1] || \"\";\n let relativePath = \"\";\n try {\n const hrefUrl = new URL(fullPath);\n relativePath = hrefUrl.pathname;\n } catch {}\n const pathRegex = new RegExp(`^/*${path}`)\n relativePath = fullPath.replace(basePath, \"\").replace(pathRegex, '').replace(/^\\//, \"\");\n if (relativePath && relativePath !== path.replace(/^\\//, \"\")) {\n files.push(relativePath);\n }\n }\n\n return files;\n }\n\n /**\n * Test connection\n */\n async testConnection(): Promise<boolean> {\n try {\n await this.listDirectory(\"\");\n return true;\n } catch {\n return false;\n }\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,gBAAb,MAAoD;CACl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AI,QAAQ,CACP;AAE5B,UAAQ,QAAQ,UAAU,KAAK,KAAK,MAAM,MAAM;GAC9C,MAAM,WAAW,MAAM,MAAM;GAC7B,IAAI,eAAe;AACnB,OAAI;AAEF,mBADgB,IAAI,IAAI,SAAS,CACV;WACjB;GACR,MAAM,4BAAY,IAAI,OAAO,MAAM,OAAO;AAC1C,kBAAe,SAAS,QAAQ,UAAU,GAAG,CAAC,QAAQ,WAAW,GAAG,CAAC,QAAQ,OAAO,GAAG;AACvF,OAAI,gBAAgB,iBAAiB,KAAK,QAAQ,OAAO,GAAG,CAC1D,OAAM,KAAK,aAAa;;AAI5B,SAAO;;;;;CAMT,MAAM,iBAAmC;AACvC,MAAI;AACF,SAAM,KAAK,cAAc,GAAG;AAC5B,UAAO;UACD;AACN,UAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["headers: Record<string, string>","files: string[]"],"sources":["../src/webdav-adapter.ts"],"sourcesContent":["import {\n AdapterType,\n type RemoteAdapter,\n type QueryOptions,\n type PaginatedResult,\n type ServiceConfig,\n AuthType,\n} from \"@omnistreamai/data-core\";\n\n/**\n * WebDAV adapter implementation\n */\nexport class WebDAVAdapter implements RemoteAdapter {\n readonly type = AdapterType.Remote;\n readonly name = \"WebDAVAdapter\";\n\n private service: ServiceConfig | null = null;\n\n /**\n * Set service configuration\n */\n setService(service: ServiceConfig): void {\n this.service = service;\n }\n\n /**\n * Get request headers\n */\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (!this.service?.authentication) {\n return headers;\n }\n\n const { authentication } = this.service;\n\n switch (authentication.authType) {\n case AuthType.Token:\n if (authentication.token) {\n headers[\"Authorization\"] =\n `${authentication.token.token_type} ${authentication.token.access_token}`;\n }\n break;\n case AuthType.Bearer:\n if (authentication.bearer) {\n headers[\"Authorization\"] = `Bearer ${authentication.bearer}`;\n }\n break;\n case AuthType.Basic:\n if (authentication.username && authentication.password) {\n const credentials = btoa(\n `${authentication.username}:${authentication.password}`,\n );\n headers[\"Authorization\"] = `Basic ${credentials}`;\n }\n break;\n }\n\n return headers;\n }\n\n /**\n * Build URL\n */\n private buildUrl(storeName: string): string {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const basePath = this.service.basePath ? `/${this.service.basePath.replace(/^\\/+|\\/+$/g, \"\")}` : \"\";\n return `${baseUrl}${basePath}/${storeName}.json`;\n }\n\n /**\n * Send request\n */\n private async request<T>(\n url: string,\n options: RequestInit = {},\n {\n allowNotFound,\n }: {\n allowNotFound?: boolean;\n } = {},\n ): Promise<T | null> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.getHeaders(),\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n if (allowNotFound && response.status == 404) {\n return null;\n }\n throw new Error(\n `HTTP error! status: ${response.status}, message: ${response.statusText}`,\n );\n }\n\n const text = await response.text();\n if (!text) {\n return null;\n }\n\n try {\n return JSON.parse(text) as T;\n } catch {\n return null;\n }\n }\n\n /**\n * Initialize store\n */\n async initStore(\n storeName: string,\n _indexes: string[] = [],\n _idKey: string = \"id\",\n ): Promise<void> {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n if (this.service.basePath) {\n const basePath = this.service.basePath.replace(/^\\/+|\\/+$/g, \"\");\n const parts = basePath.split(\"/\");\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n\n let currentPath = \"\";\n for (const part of parts) {\n currentPath = currentPath ? `${currentPath}/${part}` : part;\n\n try {\n await this.listDirectory(currentPath);\n } catch {\n const url = `${baseUrl}/${currentPath}`;\n\n const response = await fetch(url, {\n method: \"MKCOL\",\n headers: this.getHeaders(),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create base path: ${response.statusText}`);\n }\n }\n }\n }\n\n const jsonFileUrl = this.buildUrl(storeName);\n const result = await this.request<unknown[]>(jsonFileUrl, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n });\n\n if (!result) {\n const response = await fetch(jsonFileUrl, {\n method: \"PUT\",\n headers: this.getHeaders(),\n body: JSON.stringify([]),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create JSON file: ${response.statusText}`);\n }\n }\n }\n\n /**\n * Add data\n */\n async add<T extends Record<string, unknown>>(\n storeName: string,\n data: T,\n _idKey: string = \"id\",\n ): Promise<T> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<T[]>(url, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n });\n\n const items = existing || [];\n items.push(data);\n\n await this.request(url, {\n method: \"PUT\",\n body: JSON.stringify(items),\n });\n\n return data;\n }\n\n /**\n * Update data\n */\n async update<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n data: Partial<T>,\n idKey: string = \"id\",\n ): Promise<T> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<T[]>(url, {\n method: \"GET\",\n });\n\n if (!existing) {\n throw new Error(\"Not found id:\" + id);\n }\n\n const index = existing.findIndex(item => String(item[idKey]) === id);\n if (index === -1) {\n throw new Error(\"Not found id:\" + id);\n }\n\n existing[index] = { ...existing[index], ...data } as T;\n\n await this.request(url, {\n method: \"PUT\",\n body: JSON.stringify(existing),\n });\n\n return existing[index];\n }\n\n /**\n * Delete data\n */\n async delete(\n storeName: string,\n id: string,\n idKey: string = \"id\",\n ): Promise<void> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<Record<string, unknown>[]>(url, {\n method: \"GET\",\n });\n\n if (!existing) {\n throw new Error(\"Not found id:\" + id);\n }\n\n const index = existing.findIndex(item => String(item[idKey]) === id);\n if (index === -1) {\n throw new Error(\"Not found id:\" + id);\n }\n\n existing.splice(index, 1);\n\n await this.request(url, {\n method: \"PUT\",\n body: JSON.stringify(existing),\n });\n }\n\n /**\n * Get data by ID\n */\n async getData<T extends Record<string, unknown>>(\n storeName: string,\n id: string,\n idKey: string = \"id\",\n ): Promise<T | null> {\n const url = this.buildUrl(storeName);\n\n const existing = await this.request<T[]>(url, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n });\n\n if (!existing) {\n return null;\n }\n\n const item = existing.find(item => String(item[idKey]) === id);\n return item ?? null;\n }\n\n /**\n * Get list data (with pagination support)\n */\n async getList<T extends Record<string, unknown>>(\n storeName: string,\n options: QueryOptions<T> = {},\n _idKey: string = \"id\",\n ): Promise<PaginatedResult<T>> {\n const url = this.buildUrl(storeName);\n\n const allData = await this.request<T[]>(url, {\n method: \"GET\",\n }, {\n allowNotFound: true,\n }) || [];\n\n let filteredData = allData;\n\n if (options.where) {\n filteredData = allData.filter((item) => {\n for (const key in options.where) {\n const itemValue = item[key];\n const whereValue = options.where![key];\n if (itemValue !== whereValue) {\n return false;\n }\n }\n return true;\n });\n }\n\n // Sorting\n if (options.sortBy) {\n filteredData = this.sortEntries(\n filteredData,\n String(options.sortBy),\n options.sortOrder,\n );\n }\n\n const totalCount = filteredData.length;\n const page = options.page ?? 1;\n const limit = options.limit ?? totalCount;\n\n const startIndex = (page - 1) * limit;\n const endIndex = startIndex + limit;\n const paginatedData = filteredData.slice(startIndex, endIndex);\n\n return {\n data: paginatedData,\n totalCount,\n page,\n limit,\n };\n }\n\n /**\n * Sort entries by specified field\n * @param entries Array of entries to sort\n * @param key Sorting field name\n * @param sortOrder Sort order: 'asc' or 'desc' (default: 'asc')\n * @returns Sorted array of entries\n */\n private sortEntries<T extends Record<string, unknown>>(\n entries: T[],\n key: string,\n sortOrder: \"asc\" | \"desc\" = \"asc\",\n ): T[] {\n return [...entries].sort((a, b) => {\n const aValue = a[key];\n const bValue = b[key];\n\n // Handle undefined or null values\n if (aValue == null && bValue == null) return 0;\n if (aValue == null) return 1; // null/undefined at the end\n if (bValue == null) return -1; // null/undefined at the end\n\n let comparison = 0;\n\n // Number type sorting\n if (typeof aValue === \"number\" && typeof bValue === \"number\") {\n comparison = aValue - bValue;\n }\n // String type sorting\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n comparison = aValue.localeCompare(bValue);\n }\n // Date type sorting (if string format date)\n else if (typeof aValue === \"string\" && typeof bValue === \"string\") {\n const aDate = new Date(aValue);\n const bDate = new Date(bValue);\n if (!isNaN(aDate.getTime()) && !isNaN(bDate.getTime())) {\n comparison = aDate.getTime() - bDate.getTime();\n } else {\n // Convert other types to string for comparison\n comparison = String(aValue).localeCompare(String(bValue));\n }\n }\n // Convert other types to string for comparison\n else {\n comparison = String(aValue).localeCompare(String(bValue));\n }\n\n // Apply sort order\n return sortOrder === \"desc\" ? -comparison : comparison;\n });\n }\n\n /**\n * Clear store\n */\n async clear(storeName: string): Promise<void> {\n const list = await this.getList(storeName);\n\n for (const item of list.data) {\n const id = String((item as Record<string, unknown>)[\"id\"]);\n await this.delete(storeName, id);\n }\n }\n\n /**\n * List directory contents\n */\n async listDirectory(path: string = \"\"): Promise<string[]> {\n if (!this.service) {\n throw new Error(\"Service not configured. Call setService() first.\");\n }\n\n const baseUrl = this.service.endpoint.replace(/\\/$/, \"\");\n const url = path ? `${baseUrl}/${path.replace(/^\\//, \"\")}` : baseUrl;\n\n const response = await fetch(url, {\n method: \"PROPFIND\",\n headers: {\n ...this.getHeaders(),\n Depth: \"1\",\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to list directory: ${response.statusText}`);\n }\n\n const text = await response.text();\n\n const hrefRegex = /<d:href[^>]*>([^<]+)<\\/d:href>/gi;\n const files: string[] = [];\n let match;\n\n const baseUrlObj = new URL(baseUrl);\n const basePath = baseUrlObj.pathname;\n\n while ((match = hrefRegex.exec(text)) !== null) {\n const fullPath = match[1] || \"\";\n let relativePath = \"\";\n try {\n const hrefUrl = new URL(fullPath);\n relativePath = hrefUrl.pathname;\n } catch {}\n const pathRegex = new RegExp(`^/*${path}`)\n relativePath = fullPath.replace(basePath, \"\").replace(pathRegex, '').replace(/^\\//, \"\");\n if (relativePath && relativePath !== path.replace(/^\\//, \"\")) {\n files.push(relativePath);\n }\n }\n\n return files;\n }\n\n /**\n * Test connection\n */\n async testConnection(): Promise<boolean> {\n try {\n await this.listDirectory(\"\");\n return true;\n } catch {\n return false;\n }\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,gBAAb,MAAoD;CAClD,AAAS,OAAO,YAAY;CAC5B,AAAS,OAAO;CAEhB,AAAQ,UAAgC;;;;CAKxC,WAAW,SAA8B;AACvC,OAAK,UAAU;;;;;CAMjB,AAAQ,aAAqC;EAC3C,MAAMA,UAAkC,EACtC,gBAAgB,oBACjB;AAED,MAAI,CAAC,KAAK,SAAS,eACjB,QAAO;EAGT,MAAM,EAAE,mBAAmB,KAAK;AAEhC,UAAQ,eAAe,UAAvB;GACE,KAAK,SAAS;AACZ,QAAI,eAAe,MACjB,SAAQ,mBACN,GAAG,eAAe,MAAM,WAAW,GAAG,eAAe,MAAM;AAE/D;GACF,KAAK,SAAS;AACZ,QAAI,eAAe,OACjB,SAAQ,mBAAmB,UAAU,eAAe;AAEtD;GACF,KAAK,SAAS;AACZ,QAAI,eAAe,YAAY,eAAe,SAI5C,SAAQ,mBAAmB,SAHP,KAClB,GAAG,eAAe,SAAS,GAAG,eAAe,WAC9C;AAGH;;AAGJ,SAAO;;;;;CAMT,AAAQ,SAAS,WAA2B;AAC1C,MAAI,CAAC,KAAK,QACR,OAAM,IAAI,MAAM,mDAAmD;AAKrE,SAAO,GAFS,KAAK,QAAQ,SAAS,QAAQ,OAAO,GAAG,GACvC,KAAK,QAAQ,WAAW,IAAI,KAAK,QAAQ,SAAS,QAAQ,cAAc,GAAG,KAAK,GACpE,GAAG,UAAU;;;;;CAM5C,MAAc,QACZ,KACA,UAAuB,EAAE,EACzB,EACE,kBAGE,EAAE,EACa;EACnB,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,GAAG;GACH,SAAS;IACP,GAAG,KAAK,YAAY;IACpB,GAAG,QAAQ;IACZ;GACF,CAAC;AAEF,MAAI,CAAC,SAAS,IAAI;AAChB,OAAI,iBAAiB,SAAS,UAAU,IACtC,QAAO;AAET,S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