Skip to main content

Server SDK Base

The ServerSdk class provides an abstract base class for server-side SDK implementations. It includes methods for validating and executing various operations such as creating, updating, deleting, and retrieving records.

info

This is abstract class and must be extended to implement the required methods. Currently MongoServerSdk and SequelizeServerSdk are available, but you can create your own implementation based on your needs.

Constructor

constructor(options: Omit<Options, 'context'> & { context?: SdkContext })

Creates an instance of ServerSdk.

Options

NameTypeDescriptionRequired
schemaStoreISchemaStoreThe schema store.Yes
contextSdkContextThe SDK context.No
pluginStoreIPluginStoreThe plugin store.No
dataFilterIDataFilterThe data filter.No
defaultValueProviderIDefaultValueProviderThe default value provider.No
autoNumberProviderIAutoNumberProviderThe auto number provider.No

Methods

execute

public async execute(params: ExecuteParams): Promise<unknown>

Executes the operation with session management.

ExecuteParams
NameTypeDescriptionRequired
typeExecuteTypeThe type of operation.Yes
payload-The payload based on the operation type.Yes

startSesssion

protected abstract startSesssion(): Promise<void>

Starts a session.

commitSession

protected abstract commitSession(): Promise<void>

Commits the current session.

abortSession

protected abstract abortSession(): Promise<void>

Aborts the current session.

endSession

protected abstract endSession(): Promise<void>

Ends the current session.

retriveRecord

protected abstract retriveRecord<T extends Record<string, unknown>>(params: RetriveRecordParams): Promise<RetriveRecordResult<T>>

Retrieves a single record based on the provided parameters.

retriveRecords

protected abstract retriveRecords<T extends Record<string, unknown>>(params: RetriveRecordsParams): Promise<RetriveRecordsResult<T>>

Retrieves multiple records based on the provided parameters.

deleteRecord

protected abstract deleteRecord(params: DeleteRecordParams): Promise<DeleteRecordResult>

Deletes a record based on the provided parameters.

createRecord

protected abstract createRecord(params: CreateRecordParams): Promise<CreateRecordResult>

Creates a new record based on the provided parameters.

updateRecord

protected abstract updateRecord(params: UpdateRecordParams): Promise<UpdateRecordResult>

Updates an existing record based on the provided parameters.

retriveAggregate

protected abstract retriveAggregate<T = unknown>(params: AggregateQuery): Promise<T[]>

Retrieves aggregated data based on the provided parameters.

getChangedValues

protected getChangedValues<T extends Record<string, any>>(previousData: T, newData: T): ChangedValues

Gets the changed values between the previous and new data.

getDependedAttributes

protected getDependedAttributes(schema: Schema<SA>): Array<{ attributeName: string; schemaLogicalName: string; behavior?: LookupBehavior }>

Gets the attributes that depend on the given schema.