First commit: Tryton client using TypeScript
This commit is contained in:
170
index.ts
Normal file
170
index.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* Tryton RPC Client for Node.js - TypeScript Entry Point
|
||||
* Main exports for the Tryton RPC Client library
|
||||
*/
|
||||
|
||||
// Import types and classes for internal use
|
||||
import { TrytonClient } from "./client";
|
||||
import type {
|
||||
TrytonClientConfig,
|
||||
TrytonClientOptions,
|
||||
TrytonRecord,
|
||||
TrytonUser,
|
||||
TrytonError,
|
||||
} from "./types";
|
||||
|
||||
// Main client class
|
||||
export { TrytonClient } from "./client";
|
||||
export { default as TrytonClientDefault } from "./client";
|
||||
|
||||
// RPC and transport classes (Node.js only)
|
||||
export {
|
||||
ServerProxy,
|
||||
ServerPool,
|
||||
Transport,
|
||||
TrytonJSONEncoder,
|
||||
ResponseError,
|
||||
Fault,
|
||||
ProtocolError,
|
||||
} from "./jsonrpc";
|
||||
|
||||
// Cache classes
|
||||
export {
|
||||
TrytonCache,
|
||||
CacheDict,
|
||||
type CacheEntry,
|
||||
type CacheStats,
|
||||
type CacheFactory,
|
||||
} from "./cache";
|
||||
|
||||
// All type definitions
|
||||
export type {
|
||||
// Configuration types
|
||||
TrytonClientConfig,
|
||||
TrytonClientOptions,
|
||||
ServerProxyOptions,
|
||||
ServerPoolOptions,
|
||||
|
||||
// Data types
|
||||
TrytonRecord,
|
||||
TrytonUser,
|
||||
TrytonCompany,
|
||||
TrytonParty,
|
||||
|
||||
// Search and domain types
|
||||
SearchDomain,
|
||||
DomainClause,
|
||||
DomainOperator,
|
||||
DomainLogicalOperator,
|
||||
|
||||
// RPC types
|
||||
TrytonMethodCall,
|
||||
TrytonBatchCall,
|
||||
|
||||
// Authentication types
|
||||
LoginParameters,
|
||||
LoginResult,
|
||||
UserPreferences,
|
||||
|
||||
// Database types
|
||||
DatabaseInfo,
|
||||
|
||||
// Error types
|
||||
RpcError,
|
||||
|
||||
// Context types
|
||||
TrytonContext,
|
||||
|
||||
// CRUD operation types
|
||||
CreateOptions,
|
||||
ReadOptions,
|
||||
WriteOptions,
|
||||
DeleteOptions,
|
||||
SearchOptions,
|
||||
SearchReadOptions,
|
||||
|
||||
// Client state types
|
||||
ClientConfig,
|
||||
|
||||
// Utility types
|
||||
CacheEntry as CacheEntryType,
|
||||
ModelName,
|
||||
FieldName,
|
||||
RecordId,
|
||||
RecordIds,
|
||||
TypedModelOperations,
|
||||
} from "./types";
|
||||
|
||||
// Re-export error class for convenience
|
||||
export { TrytonError } from "./types";
|
||||
|
||||
// Version information
|
||||
export const VERSION = "1.1.0";
|
||||
|
||||
// Default export is the main client
|
||||
export default TrytonClient;
|
||||
|
||||
// Convenience factory functions
|
||||
export function createClient(config: TrytonClientConfig): TrytonClient {
|
||||
return new TrytonClient(config);
|
||||
}
|
||||
|
||||
export function createTrytonClient(
|
||||
hostname: string,
|
||||
database: string,
|
||||
username: string,
|
||||
password: string,
|
||||
port?: number,
|
||||
language?: string
|
||||
): TrytonClient {
|
||||
return TrytonClient.create(
|
||||
hostname,
|
||||
database,
|
||||
username,
|
||||
password,
|
||||
port,
|
||||
language
|
||||
);
|
||||
}
|
||||
|
||||
// Type guard functions
|
||||
export function isTrytonRecord(obj: any): obj is TrytonRecord {
|
||||
return obj && typeof obj === "object" && typeof obj.id === "number";
|
||||
}
|
||||
|
||||
export function isTrytonUser(obj: any): obj is TrytonUser {
|
||||
return (
|
||||
isTrytonRecord(obj) &&
|
||||
typeof obj.login === "string" &&
|
||||
typeof obj.name === "string"
|
||||
);
|
||||
}
|
||||
|
||||
export function isTrytonError(error: any): error is TrytonError {
|
||||
return error instanceof Error && error.name === "TrytonError";
|
||||
}
|
||||
|
||||
// Helper functions for React Context
|
||||
export interface ReactTrytonContextConfig {
|
||||
hostname?: string;
|
||||
database?: string;
|
||||
port?: number;
|
||||
language?: string;
|
||||
options?: TrytonClientOptions;
|
||||
}
|
||||
|
||||
export function createReactTrytonConfig(
|
||||
baseConfig: ReactTrytonContextConfig,
|
||||
username: string,
|
||||
password: string
|
||||
): TrytonClientConfig {
|
||||
return {
|
||||
hostname: baseConfig.hostname || "localhost",
|
||||
database: baseConfig.database || "tryton",
|
||||
username,
|
||||
password,
|
||||
port: baseConfig.port || 8000,
|
||||
language: baseConfig.language || "en",
|
||||
options: baseConfig.options || {},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user