viyv-db-remote 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 viyv
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ import { ViyvDbError } from 'viyv-db-core';
2
+ import type { RpcErrorBody } from 'viyv-db-core/rpc';
3
+ /**
4
+ * Deserializes an RPC error response into the appropriate ViyvDbError subclass.
5
+ * Preserves the original error message from the server.
6
+ */
7
+ export declare function deserializeError(error: RpcErrorBody): ViyvDbError;
8
+ //# sourceMappingURL=error-deserializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-deserializer.d.ts","sourceRoot":"","sources":["../src/error-deserializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,WAAW,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAwBjE"}
@@ -0,0 +1,31 @@
1
+ import { AuthenticationError, AuthorizationError, MigrationError, SemanticSearchNotEnabledError, SqlValidationError, ViyvDbError, } from 'viyv-db-core';
2
+ /**
3
+ * Deserializes an RPC error response into the appropriate ViyvDbError subclass.
4
+ * Preserves the original error message from the server.
5
+ */
6
+ export function deserializeError(error) {
7
+ switch (error.code) {
8
+ case 'TABLE_NOT_FOUND':
9
+ case 'SYSTEM_TABLE':
10
+ case 'ACCESS_DENIED':
11
+ return new ViyvDbError(error.message, error.code);
12
+ case 'MIGRATION_ERROR':
13
+ return new MigrationError(error.message);
14
+ case 'SQL_VALIDATION':
15
+ return new SqlValidationError(error.message);
16
+ case 'SEMANTIC_SEARCH_NOT_ENABLED':
17
+ return new SemanticSearchNotEnabledError();
18
+ case 'AUTHENTICATION_FAILED':
19
+ return new AuthenticationError(error.message);
20
+ case 'AUTHORIZATION_DENIED': {
21
+ const match = error.message.match(/^Authorization denied for "(.+?)": (.+)$/);
22
+ if (match) {
23
+ return new AuthorizationError(match[1], match[2]);
24
+ }
25
+ return new AuthorizationError('unknown', error.message);
26
+ }
27
+ default:
28
+ return new ViyvDbError(error.message, error.code);
29
+ }
30
+ }
31
+ //# sourceMappingURL=error-deserializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-deserializer.js","sourceRoot":"","sources":["../src/error-deserializer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,6BAA6B,EAC7B,kBAAkB,EAClB,WAAW,GACX,MAAM,cAAc,CAAC;AAGtB;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAmB;IACnD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,iBAAiB,CAAC;QACvB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YACnB,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnD,KAAK,iBAAiB;YACrB,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,gBAAgB;YACpB,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,6BAA6B;YACjC,OAAO,IAAI,6BAA6B,EAAE,CAAC;QAC5C,KAAK,uBAAuB;YAC3B,OAAO,IAAI,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/C,KAAK,sBAAsB,CAAC,CAAC,CAAC;YAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAC9E,IAAI,KAAK,EAAE,CAAC;gBACX,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,CAAC;YACD,OAAO,IAAI,kBAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;QACD;YACC,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;AACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ICredentialStore } from 'viyv-db-auth';
2
+ export interface HttpClientConfig {
3
+ timeoutMs: number;
4
+ maxRetries: number;
5
+ }
6
+ export declare class HttpClient {
7
+ private readonly baseUrl;
8
+ private readonly credentialStore;
9
+ private readonly config;
10
+ constructor(baseUrl: string, credentialStore: ICredentialStore | null, config?: Partial<HttpClientConfig>);
11
+ post<T>(path: string, body: unknown): Promise<T>;
12
+ private doRequest;
13
+ }
14
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACnB;AAOD,qBAAa,UAAU;IAIrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAJjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;gBAGxB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,gBAAgB,GAAG,IAAI,EACzD,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAK7B,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;YAIxC,SAAS;CA8DvB"}
@@ -0,0 +1,72 @@
1
+ import { getValidToken, refreshTokens } from 'viyv-db-auth';
2
+ const DEFAULT_CONFIG = {
3
+ timeoutMs: 30_000,
4
+ maxRetries: 2,
5
+ };
6
+ export class HttpClient {
7
+ baseUrl;
8
+ credentialStore;
9
+ config;
10
+ constructor(baseUrl, credentialStore, config) {
11
+ this.baseUrl = baseUrl;
12
+ this.credentialStore = credentialStore;
13
+ this.config = { ...DEFAULT_CONFIG, ...config };
14
+ }
15
+ async post(path, body) {
16
+ return this.doRequest(path, body, 0, false);
17
+ }
18
+ async doRequest(path, body, attempt, forceRefresh) {
19
+ const headers = {
20
+ 'Content-Type': 'application/json',
21
+ };
22
+ // Attach Bearer token if credential store is available
23
+ if (this.credentialStore) {
24
+ if (forceRefresh) {
25
+ // Force token refresh (e.g. after 401)
26
+ const creds = await this.credentialStore.load();
27
+ if (creds) {
28
+ const newTokens = await refreshTokens(creds, this.credentialStore);
29
+ headers.Authorization = `Bearer ${newTokens.accessToken}`;
30
+ }
31
+ }
32
+ else {
33
+ const result = await getValidToken(this.credentialStore);
34
+ if (result) {
35
+ headers.Authorization = `Bearer ${result.token}`;
36
+ }
37
+ }
38
+ }
39
+ const controller = new AbortController();
40
+ const timer = setTimeout(() => controller.abort(), this.config.timeoutMs);
41
+ try {
42
+ const response = await fetch(`${this.baseUrl}${path}`, {
43
+ method: 'POST',
44
+ headers,
45
+ body: JSON.stringify(body),
46
+ signal: controller.signal,
47
+ });
48
+ // 401: force token refresh and retry once
49
+ if (response.status === 401 && attempt === 0 && this.credentialStore) {
50
+ return this.doRequest(path, body, attempt + 1, true);
51
+ }
52
+ // 5xx: retry
53
+ if (response.status >= 500 && attempt < this.config.maxRetries) {
54
+ return this.doRequest(path, body, attempt + 1, false);
55
+ }
56
+ if (!response.ok && response.status !== 400) {
57
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
58
+ }
59
+ return (await response.json());
60
+ }
61
+ catch (error) {
62
+ if (error instanceof DOMException && error.name === 'AbortError') {
63
+ throw new Error(`Request timed out after ${this.config.timeoutMs}ms`);
64
+ }
65
+ throw error;
66
+ }
67
+ finally {
68
+ clearTimeout(timer);
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=http-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAO5D,MAAM,cAAc,GAAqB;IACxC,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,CAAC;CACb,CAAC;AAEF,MAAM,OAAO,UAAU;IAIJ;IACA;IAJD,MAAM,CAAmB;IAE1C,YACkB,OAAe,EACf,eAAwC,EACzD,MAAkC;QAFjB,YAAO,GAAP,OAAO,CAAQ;QACf,oBAAe,GAAf,eAAe,CAAyB;QAGzD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IAChD,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';
3
+ import { RemoteDatabaseService } from './remote-service.js';
4
+ export { RemoteDatabaseService } from './remote-service.js';
5
+ export { HttpClient } from './http-client.js';
6
+ export { deserializeError } from './error-deserializer.js';
7
+ export interface RemoteConfig extends Partial<BaseConfig> {
8
+ timeoutMs?: number;
9
+ maxRetries?: number;
10
+ }
11
+ /**
12
+ * Creates a RemoteDatabaseService that proxies all operations over HTTP
13
+ * to a viyv-db server endpoint.
14
+ */
15
+ export declare function createRemoteService(url: string, credentialStore: ICredentialStore | null, config?: RemoteConfig): RemoteDatabaseService;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,YAAa,SAAQ,OAAO,CAAC,UAAU,CAAC;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,MAAM,EACX,eAAe,EAAE,gBAAgB,GAAG,IAAI,EACxC,MAAM,CAAC,EAAE,YAAY,GACnB,qBAAqB,CAMvB"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import { HttpClient } from './http-client.js';
2
+ import { RemoteDatabaseService } from './remote-service.js';
3
+ export { RemoteDatabaseService } from './remote-service.js';
4
+ export { HttpClient } from './http-client.js';
5
+ export { deserializeError } from './error-deserializer.js';
6
+ /**
7
+ * Creates a RemoteDatabaseService that proxies all operations over HTTP
8
+ * to a viyv-db server endpoint.
9
+ */
10
+ export function createRemoteService(url, credentialStore, config) {
11
+ const http = new HttpClient(url, credentialStore, {
12
+ timeoutMs: config?.timeoutMs ?? config?.queryTimeoutMs ?? 30_000,
13
+ maxRetries: config?.maxRetries ?? 2,
14
+ });
15
+ return new RemoteDatabaseService(http);
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAO3D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,GAAW,EACX,eAAwC,EACxC,MAAqB;IAErB,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE;QACjD,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,MAAM,EAAE,cAAc,IAAI,MAAM;QAChE,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,CAAC;KACnC,CAAC,CAAC;IACH,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { AlterAction, CreateTableDef, IDatabaseService, InsertResult, Migration, MutationResult, QueryResult, QueryTableOptions, SchemaMode, SchemaOptions, SchemaResult, SemanticSearchOptions, SemanticSearchResult } from 'viyv-db-core';
2
+ import type { HttpClient } from './http-client.js';
3
+ export declare class RemoteDatabaseService implements IDatabaseService {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ private call;
7
+ initialize(): Promise<void>;
8
+ close(): Promise<void>;
9
+ getSchema(mode: SchemaMode, options?: SchemaOptions): Promise<SchemaResult>;
10
+ createTable(def: CreateTableDef, reason: string, appliedBy?: string): Promise<void>;
11
+ alterTable(table: string, action: AlterAction, reason: string, appliedBy?: string): Promise<void>;
12
+ dropTable(table: string, reason: string, appliedBy?: string): Promise<void>;
13
+ insert(table: string, rows: Record<string, unknown>[]): Promise<InsertResult>;
14
+ update(table: string, set: Record<string, unknown>, where: Record<string, unknown>): Promise<MutationResult>;
15
+ delete(table: string, where: Record<string, unknown>): Promise<MutationResult>;
16
+ upsert(table: string, rows: Record<string, unknown>[], conflictColumns: string[]): Promise<InsertResult>;
17
+ query(sql: string, params?: unknown[]): Promise<QueryResult>;
18
+ executeSql(sql: string, params?: unknown[], accessLevel?: string): Promise<QueryResult>;
19
+ queryTable(table: string, options?: QueryTableOptions): Promise<QueryResult>;
20
+ getMigrationInfo(): Promise<Migration[]>;
21
+ rollbackMigration(targetVersion: string): Promise<void>;
22
+ semanticSearch(options: SemanticSearchOptions): Promise<SemanticSearchResult[]>;
23
+ }
24
+ //# sourceMappingURL=remote-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-service.d.ts","sourceRoot":"","sources":["../src/remote-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAa,qBAAsB,YAAW,gBAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;YAG/B,IAAI;IASZ,UAAU,IAAI,OAAO,CAAC,IAA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C,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIvF,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5E,gBAAgB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIxC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;CAGrF"}
@@ -0,0 +1,66 @@
1
+ import { RPC_VERSION } from 'viyv-db-core/rpc';
2
+ import { deserializeError } from './error-deserializer.js';
3
+ export class RemoteDatabaseService {
4
+ http;
5
+ constructor(http) {
6
+ this.http = http;
7
+ }
8
+ // biome-ignore lint/suspicious/noExplicitAny: RPC dispatch requires flexible return types
9
+ async call(method, params) {
10
+ const body = { version: RPC_VERSION, method, params };
11
+ const res = await this.http.post('/rpc', body);
12
+ if (!res.ok) {
13
+ throw deserializeError(res.error);
14
+ }
15
+ return res.result;
16
+ }
17
+ async initialize() {
18
+ // No-op: server handles initialization
19
+ }
20
+ async close() {
21
+ // No-op: server manages connections
22
+ }
23
+ async getSchema(mode, options) {
24
+ return this.call('getSchema', { mode, options });
25
+ }
26
+ async createTable(def, reason, appliedBy) {
27
+ return this.call('createTable', { def, reason, appliedBy });
28
+ }
29
+ async alterTable(table, action, reason, appliedBy) {
30
+ return this.call('alterTable', { table, action, reason, appliedBy });
31
+ }
32
+ async dropTable(table, reason, appliedBy) {
33
+ return this.call('dropTable', { table, reason, appliedBy });
34
+ }
35
+ async insert(table, rows) {
36
+ return this.call('insert', { table, rows });
37
+ }
38
+ async update(table, set, where) {
39
+ return this.call('update', { table, set, where });
40
+ }
41
+ async delete(table, where) {
42
+ return this.call('delete', { table, where });
43
+ }
44
+ async upsert(table, rows, conflictColumns) {
45
+ return this.call('upsert', { table, rows, conflictColumns });
46
+ }
47
+ async query(sql, params) {
48
+ return this.call('query', { sql, params });
49
+ }
50
+ async executeSql(sql, params, accessLevel) {
51
+ return this.call('executeSql', { sql, params, accessLevel });
52
+ }
53
+ async queryTable(table, options) {
54
+ return this.call('queryTable', { table, options });
55
+ }
56
+ async getMigrationInfo() {
57
+ return this.call('getMigrationInfo', {});
58
+ }
59
+ async rollbackMigration(targetVersion) {
60
+ return this.call('rollbackMigration', { targetVersion });
61
+ }
62
+ async semanticSearch(options) {
63
+ return this.call('semanticSearch', { options });
64
+ }
65
+ }
66
+ //# sourceMappingURL=remote-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-service.js","sourceRoot":"","sources":["../src/remote-service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,OAAO,qBAAqB;IACJ;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,0FAA0F;IAClF,KAAK,CAAC,IAAI,CAAC,MAAiB,EAAE,MAAW;QAChD,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QACtD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAc,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,UAAU;QACf,uCAAuC;IACxC,CAAC;IAED,KAAK,CAAC,KAAK;QACV,oCAAoC;IACrC,CAAC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AC/B,eAAyB;QAEzB,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,MAAkB;QAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,MAAkB,EAAE,WAAoB;QACrE,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,OAA2B;QAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,aAAqB;QAC5C,OAAO,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA8B;QAClD,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;CACD"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "viyv-db-remote",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Remote database service client for viyv-db",
6
+ "license": "MIT",
7
+ "author": "viyv",
8
+ "engines": {
9
+ "node": ">=20"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "!dist/__tests__"
22
+ ],
23
+ "dependencies": {
24
+ "viyv-db-core": "0.1.0",
25
+ "viyv-db-auth": "0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.7.0",
29
+ "vitest": "^2.1.0"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "typecheck": "tsc --noEmit",
34
+ "test": "vitest run",
35
+ "clean": "rm -rf dist"
36
+ }
37
+ }