285 lines
5.9 KiB
TypeScript
285 lines
5.9 KiB
TypeScript
/**
|
|
* TypeScript type definitions for Tryton RPC Client
|
|
*/
|
|
|
|
// Forward declarations
|
|
declare class TrytonCache {
|
|
cached(prefix: string): boolean;
|
|
get(prefix: string, key: string): any;
|
|
set(prefix: string, key: string, expire: number | Date, value: any): void;
|
|
clear(prefix?: string): void;
|
|
}
|
|
|
|
// ===== CONFIGURATION TYPES =====
|
|
|
|
export interface TrytonClientConfig {
|
|
hostname: string;
|
|
database: string;
|
|
username: string;
|
|
password: string;
|
|
port?: number;
|
|
language?: string;
|
|
options?: TrytonClientOptions;
|
|
}
|
|
|
|
export interface TrytonClientOptions {
|
|
verbose?: boolean;
|
|
connectTimeout?: number;
|
|
timeout?: number;
|
|
keepMax?: number;
|
|
cache?: boolean | any[];
|
|
useHttps?: boolean;
|
|
}
|
|
|
|
// ===== SERVER PROXY TYPES =====
|
|
|
|
export interface ServerProxyOptions {
|
|
verbose?: boolean;
|
|
connectTimeout?: number;
|
|
timeout?: number;
|
|
useHttps?: boolean;
|
|
fingerprints?: string[] | null;
|
|
caCerts?: string[] | null;
|
|
session?: string | null;
|
|
cache?: TrytonCache | any[] | null;
|
|
}
|
|
export interface ServerPoolOptions extends ServerProxyOptions {
|
|
session?: string;
|
|
cache?: any[] | null;
|
|
keepMax?: number;
|
|
}
|
|
|
|
// ===== TRYTON DATA TYPES =====
|
|
|
|
export interface TrytonRecord {
|
|
id: number;
|
|
[key: string]: any;
|
|
}
|
|
|
|
export interface TrytonUser extends TrytonRecord {
|
|
id: number;
|
|
name: string;
|
|
login: string;
|
|
language: string;
|
|
company: number;
|
|
email?: string;
|
|
active?: boolean;
|
|
}
|
|
|
|
export interface TrytonCompany extends TrytonRecord {
|
|
id: number;
|
|
name: string;
|
|
code?: string;
|
|
currency?: number;
|
|
}
|
|
|
|
export interface TrytonParty extends TrytonRecord {
|
|
id: number;
|
|
name: string;
|
|
code?: string;
|
|
active?: boolean;
|
|
categories?: number[];
|
|
addresses?: number[];
|
|
}
|
|
|
|
// ===== SEARCH AND DOMAIN TYPES =====
|
|
|
|
export type DomainOperator =
|
|
| "="
|
|
| "!="
|
|
| "<"
|
|
| "<="
|
|
| ">"
|
|
| ">="
|
|
| "like"
|
|
| "ilike"
|
|
| "not like"
|
|
| "not ilike"
|
|
| "in"
|
|
| "not in"
|
|
| "child_of"
|
|
| "parent_of";
|
|
|
|
export type DomainClause = [string, DomainOperator, any];
|
|
export type DomainLogicalOperator = "AND" | "OR" | "NOT";
|
|
export type SearchDomain = (
|
|
| DomainClause
|
|
| DomainLogicalOperator
|
|
| SearchDomain
|
|
)[];
|
|
|
|
// ===== RPC METHOD CALL TYPES =====
|
|
|
|
export interface TrytonMethodCall {
|
|
method: string;
|
|
args: any[];
|
|
}
|
|
|
|
export interface TrytonBatchCall extends TrytonMethodCall {
|
|
id?: string | number;
|
|
}
|
|
|
|
// ===== AUTHENTICATION TYPES =====
|
|
|
|
export interface LoginParameters {
|
|
password: string;
|
|
[key: string]: any;
|
|
}
|
|
|
|
export interface LoginResult extends Array<any> {
|
|
0: number; // user id
|
|
1: string; // session token
|
|
[key: number]: any;
|
|
}
|
|
|
|
export interface UserPreferences {
|
|
user: number;
|
|
language: string;
|
|
timezone?: string;
|
|
company?: number;
|
|
[key: string]: any;
|
|
}
|
|
|
|
// ===== DATABASE TYPES =====
|
|
|
|
export interface DatabaseInfo {
|
|
name: string;
|
|
version?: string;
|
|
[key: string]: any;
|
|
}
|
|
|
|
// ===== ERROR TYPES =====
|
|
|
|
export class TrytonError extends Error {
|
|
public readonly code?: string | number | undefined;
|
|
public readonly type?: string | undefined;
|
|
|
|
constructor(
|
|
message: string,
|
|
code?: string | number | undefined,
|
|
type?: string | undefined
|
|
) {
|
|
super(message);
|
|
this.name = "TrytonError";
|
|
this.code = code;
|
|
this.type = type;
|
|
Object.setPrototypeOf(this, TrytonError.prototype);
|
|
}
|
|
}
|
|
|
|
export interface RpcError {
|
|
message: string;
|
|
code?: string | number;
|
|
type?: string;
|
|
args?: any[];
|
|
}
|
|
|
|
// ===== CONTEXT TYPES =====
|
|
|
|
export interface TrytonContext {
|
|
language?: string;
|
|
user?: number;
|
|
company?: number;
|
|
date?: string;
|
|
timezone?: string;
|
|
groups?: number[];
|
|
[key: string]: any;
|
|
}
|
|
|
|
// ===== CRUD OPERATION TYPES =====
|
|
|
|
export interface CreateOptions {
|
|
context?: TrytonContext;
|
|
}
|
|
|
|
export interface ReadOptions {
|
|
context?: TrytonContext;
|
|
}
|
|
|
|
export interface WriteOptions {
|
|
context?: TrytonContext;
|
|
}
|
|
|
|
export interface DeleteOptions {
|
|
context?: TrytonContext;
|
|
}
|
|
|
|
export interface SearchOptions {
|
|
offset?: number;
|
|
limit?: number | null;
|
|
order?: string[] | null;
|
|
context?: TrytonContext;
|
|
}
|
|
|
|
export interface SearchReadOptions extends SearchOptions {
|
|
fields: string[];
|
|
}
|
|
|
|
// ===== CLIENT STATE TYPES =====
|
|
|
|
export interface ClientConfig {
|
|
hostname: string;
|
|
database: string;
|
|
username: string;
|
|
port: number;
|
|
language: string;
|
|
isConnected: boolean;
|
|
ssl: boolean | null;
|
|
url: string | null;
|
|
}
|
|
|
|
// ===== UTILITY TYPES =====
|
|
|
|
export type Awaitable<T> = T | Promise<T>;
|
|
|
|
export interface CacheEntry {
|
|
key: string;
|
|
value: any;
|
|
timestamp: number;
|
|
}
|
|
|
|
// ===== GENERIC MODEL TYPES =====
|
|
|
|
export type ModelName = string;
|
|
export type FieldName = string;
|
|
export type RecordId = number;
|
|
export type RecordIds = number[];
|
|
|
|
// Helper type for typed model operations
|
|
export interface TypedModelOperations<T extends TrytonRecord = TrytonRecord> {
|
|
read(
|
|
ids: RecordIds,
|
|
fields: FieldName[],
|
|
context?: TrytonContext
|
|
): Promise<T[]>;
|
|
create(
|
|
records: Partial<Omit<T, "id">>[],
|
|
context?: TrytonContext
|
|
): Promise<RecordIds>;
|
|
write(
|
|
ids: RecordIds,
|
|
values: Partial<Omit<T, "id">>,
|
|
context?: TrytonContext
|
|
): Promise<void>;
|
|
delete(ids: RecordIds, context?: TrytonContext): Promise<void>;
|
|
search(
|
|
domain: SearchDomain,
|
|
offset?: number,
|
|
limit?: number,
|
|
order?: string[],
|
|
context?: TrytonContext
|
|
): Promise<RecordIds>;
|
|
searchRead(
|
|
domain: SearchDomain,
|
|
fields: FieldName[],
|
|
offset?: number,
|
|
limit?: number,
|
|
order?: string[],
|
|
context?: TrytonContext
|
|
): Promise<T[]>;
|
|
searchCount(domain: SearchDomain, context?: TrytonContext): Promise<number>;
|
|
}
|
|
|
|
// ===== EXPORT ALL TYPES =====
|
|
// Note: All types are already exported above individually
|