Skip to content

Commit

Permalink
gen latest and add more methods to trainee
Browse files Browse the repository at this point in the history
  • Loading branch information
fulpm committed Oct 4, 2024
1 parent 85f07ce commit 582bec9
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 60 deletions.
8 changes: 4 additions & 4 deletions codegen/templates/client/AbstractBaseClient.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Generated via Howso Engine {{ version }}
*/
import type { Session, Trainee } from "../engine";
import type { ClientResponse } from "../types";
import type { BaseTrainee, ClientResponse } from "../types";
import type * as schemas from "../types/schemas";
import type * as shims from "../types/shims";
import { DEFAULT_ERROR_MESSAGE, HowsoError, HowsoValidationError } from "./errors";
Expand Down Expand Up @@ -126,7 +126,7 @@ export abstract class AbstractBaseClient {
public abstract createTrainee(properties: Omit<Trainee, "id">): Promise<Trainee>;

/** Update an existing Trainee. */
public abstract updateTrainee(trainee: Trainee): Promise<Trainee>;
public abstract updateTrainee(trainee: BaseTrainee): Promise<Trainee>;

/** Copy an existing Trainee. */
public abstract copyTrainee(traineeId: string, name?: string): Promise<Trainee>;
Expand Down Expand Up @@ -169,9 +169,9 @@ export abstract class AbstractBaseClient {
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async {{ label | camelCase }}(traineeId: string{% if def.parameters %}, request: {{ requestName }}{% endif %}): Promise<ClientResponse<{% if def.returns %}{{ responseName }}{% elif label in shims %}{{ shims[label] }}{% else %}any{% endif %}>> {
public async {{ label | camelCase }}(traineeId: string{% if def.parameters | length %}, request: {{ requestName }}{% endif %}): Promise<ClientResponse<{% if def.returns %}{{ responseName }}{% elif label in shims %}{{ shims[label] }}{% else %}any{% endif %}>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<{% if def.returns %}{{ responseName }}{% elif label in shims %}{{ shims[label] }}{% else %}any{% endif %}>(trainee.id, "{{ label }}", {% if def.parameters %}request{% else %}{}{% endif %});
const response = await this.execute<{% if def.returns %}{{ responseName }}{% elif label in shims %}{{ shims[label] }}{% else %}any{% endif %}>(trainee.id, "{{ label }}", {% if def.parameters | length %}request{% else %}{}{% endif %});
{%- if not def.read_only %}
this.autoPersistTrainee(trainee.id);
{%- endif %}
Expand Down
37 changes: 35 additions & 2 deletions codegen/templates/engine/Trainee.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Trainee implements BaseTrainee {
protected _name: BaseTrainee["name"];
protected _persistence: BaseTrainee["persistence"];
protected _metadata: BaseTrainee["metadata"];
protected _deleted = false;

constructor(client: AbstractBaseClient, obj: BaseTrainee) {
this.client = client;
Expand All @@ -38,6 +39,38 @@ export class Trainee implements BaseTrainee {
return this._metadata || {};
}

public get isDeleted(): boolean {
return this._deleted;
}

public async update(properties: Partial<BaseTrainee>): Promise<void> {
const trainee = await this.client.updateTrainee({ ...properties, id: this.id });
this._name = trainee.name;
this._metadata = trainee.metadata;
this._persistence = trainee.persistence;
}

public async delete(): Promise<void> {
await this.client.deleteTrainee(this.id);
this._deleted = true;
}

public async copy(name?: string): Promise<Trainee> {
return await this.client.copyTrainee(this.id, name);
}

public async acquireResources(): Promise<void> {
return await this.client.acquireTraineeResources(this.id);
}

public async releaseResources(): Promise<void> {
return await this.client.releaseTraineeResources(this.id);
}

public async persist(): Promise<void> {
await this.client.persistTrainee(this.id);
}

/**
* Train data into the Trainee using batched requests to the Engine.
* @param traineeId The Trainee identifier.
Expand Down Expand Up @@ -91,8 +124,8 @@ export class Trainee implements BaseTrainee {
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async {{ label | camelCase }}({% if def.parameters %}request: {{ requestName }}{% endif %}) {
return this.client.{{ label | camelCase }}(this.id, {% if def.parameters %}request{% endif %});
public async {{ label | camelCase }}({% if def.parameters | length %}request: {{ requestName }}{% endif %}) {
return this.client.{{ label | camelCase }}(this.id, {% if def.parameters | length %}request{% endif %});
}
{%- if not loop.last %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/schemas/label.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- include "schemas/_header.njk" %}
{%- from "schemas/_macros.njk" import field, comment %}
{% if parameters %}
{% if parameters | length %}
export type {{ name }}Request = {
{%- for key, schema in parameters | dictsort -%}
{{ comment(schema) | indent(2) }}
Expand Down
Binary file modified src/assets/howso.caml
Binary file not shown.
Binary file modified src/assets/migrations.caml
Binary file not shown.
99 changes: 63 additions & 36 deletions src/client/AbstractBaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Generated via Howso Engine 86.1.0+alpha
*/
import type { Session, Trainee } from "../engine";
import type { ClientResponse } from "../types";
import type { BaseTrainee, ClientResponse } from "../types";
import type * as schemas from "../types/schemas";
import type * as shims from "../types/shims";
import { DEFAULT_ERROR_MESSAGE, HowsoError, HowsoValidationError } from "./errors";
Expand Down Expand Up @@ -126,7 +126,7 @@ export abstract class AbstractBaseClient {
public abstract createTrainee(properties: Omit<Trainee, "id">): Promise<Trainee>;

/** Update an existing Trainee. */
public abstract updateTrainee(trainee: Trainee): Promise<Trainee>;
public abstract updateTrainee(trainee: BaseTrainee): Promise<Trainee>;

/** Copy an existing Trainee. */
public abstract copyTrainee(traineeId: string, name?: string): Promise<Trainee>;
Expand Down Expand Up @@ -257,9 +257,9 @@ export abstract class AbstractBaseClient {
public async createSubtrainee(
traineeId: string,
request: schemas.CreateSubtraineeRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.CreateSubtraineeResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "create_subtrainee", request);
const response = await this.execute<schemas.CreateSubtraineeResponse>(trainee.id, "create_subtrainee", request);
this.autoPersistTrainee(trainee.id);
return { payload: response.payload, warnings: response.warnings };
}
Expand Down Expand Up @@ -316,9 +316,12 @@ export abstract class AbstractBaseClient {
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async evaluate(traineeId: string, request: schemas.EvaluateRequest): Promise<ClientResponse<any>> {
public async evaluate(
traineeId: string,
request: schemas.EvaluateRequest,
): Promise<ClientResponse<schemas.EvaluateResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "evaluate", request);
const response = await this.execute<schemas.EvaluateResponse>(trainee.id, "evaluate", request);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -331,9 +334,13 @@ export abstract class AbstractBaseClient {
public async executeOnSubtrainee(
traineeId: string,
request: schemas.ExecuteOnSubtraineeRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.ExecuteOnSubtraineeResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "execute_on_subtrainee", request);
const response = await this.execute<schemas.ExecuteOnSubtraineeResponse>(
trainee.id,
"execute_on_subtrainee",
request,
);
this.autoPersistTrainee(trainee.id);
return { payload: response.payload, warnings: response.warnings };
}
Expand Down Expand Up @@ -383,19 +390,16 @@ export abstract class AbstractBaseClient {

/**
* Returns an assoc with case distances, containing a list of case session indices and a list of lists (matrix) of the computed distances.
* in the following format:
* {
* 'column_case_indices' : [ session-indices ],
* 'row_case_indices' : [ session-indices ],
* 'distances': [ [ pairwise distances ] ]
* }
* @param traineeId The Trainee identifier.
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async getDistances(traineeId: string, request: schemas.GetDistancesRequest): Promise<ClientResponse<any>> {
public async getDistances(
traineeId: string,
request: schemas.GetDistancesRequest,
): Promise<ClientResponse<schemas.GetDistancesResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_distances", request);
const response = await this.execute<schemas.GetDistancesResponse>(trainee.id, "get_distances", request);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -410,9 +414,13 @@ export abstract class AbstractBaseClient {
public async getEntityPathById(
traineeId: string,
request: schemas.GetEntityPathByIdRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetEntityPathByIdResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_entity_path_by_id", request);
const response = await this.execute<schemas.GetEntityPathByIdResponse>(
trainee.id,
"get_entity_path_by_id",
request,
);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -437,9 +445,9 @@ export abstract class AbstractBaseClient {
public async getExtremeCases(
traineeId: string,
request: schemas.GetExtremeCasesRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetExtremeCasesResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_extreme_cases", request);
const response = await this.execute<schemas.GetExtremeCasesResponse>(trainee.id, "get_extreme_cases", request);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -465,9 +473,13 @@ export abstract class AbstractBaseClient {
public async getFeatureConviction(
traineeId: string,
request: schemas.GetFeatureConvictionRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetFeatureConvictionResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_feature_conviction", request);
const response = await this.execute<schemas.GetFeatureConvictionResponse>(
trainee.id,
"get_feature_conviction",
request,
);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -478,9 +490,9 @@ export abstract class AbstractBaseClient {
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async getHierarchy(traineeId: string): Promise<ClientResponse<any>> {
public async getHierarchy(traineeId: string): Promise<ClientResponse<schemas.GetHierarchyResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_hierarchy", {});
const response = await this.execute<schemas.GetHierarchyResponse>(trainee.id, "get_hierarchy", {});
return { payload: response.payload, warnings: response.warnings };
}

Expand Down Expand Up @@ -519,9 +531,9 @@ export abstract class AbstractBaseClient {
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async getNumTrainingCases(traineeId: string): Promise<ClientResponse<any>> {
public async getNumTrainingCases(traineeId: string): Promise<ClientResponse<schemas.GetNumTrainingCasesResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_num_training_cases", {});
const response = await this.execute<schemas.GetNumTrainingCasesResponse>(trainee.id, "get_num_training_cases", {});
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -535,9 +547,13 @@ export abstract class AbstractBaseClient {
public async getPairwiseDistances(
traineeId: string,
request: schemas.GetPairwiseDistancesRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetPairwiseDistancesResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_pairwise_distances", request);
const response = await this.execute<schemas.GetPairwiseDistancesResponse>(
trainee.id,
"get_pairwise_distances",
request,
);
return { payload: response.payload, warnings: response.warnings };
}

Expand Down Expand Up @@ -575,9 +591,12 @@ export abstract class AbstractBaseClient {
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
*/
public async getSessions(traineeId: string, request: schemas.GetSessionsRequest): Promise<ClientResponse<any>> {
public async getSessions(
traineeId: string,
request: schemas.GetSessionsRequest,
): Promise<ClientResponse<schemas.GetSessionsResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_sessions", request);
const response = await this.execute<schemas.GetSessionsResponse>(trainee.id, "get_sessions", request);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -591,9 +610,9 @@ export abstract class AbstractBaseClient {
public async getSessionIndices(
traineeId: string,
request: schemas.GetSessionIndicesRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetSessionIndicesResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_session_indices", request);
const response = await this.execute<schemas.GetSessionIndicesResponse>(trainee.id, "get_session_indices", request);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -606,9 +625,13 @@ export abstract class AbstractBaseClient {
public async getSessionMetadata(
traineeId: string,
request: schemas.GetSessionMetadataRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetSessionMetadataResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_session_metadata", request);
const response = await this.execute<schemas.GetSessionMetadataResponse>(
trainee.id,
"get_session_metadata",
request,
);
return { payload: response.payload, warnings: response.warnings };
}

Expand All @@ -622,9 +645,13 @@ export abstract class AbstractBaseClient {
public async getSessionTrainingIndices(
traineeId: string,
request: schemas.GetSessionTrainingIndicesRequest,
): Promise<ClientResponse<any>> {
): Promise<ClientResponse<schemas.GetSessionTrainingIndicesResponse>> {
const trainee = await this.autoResolveTrainee(traineeId);
const response = await this.execute<any>(trainee.id, "get_session_training_indices", request);
const response = await this.execute<schemas.GetSessionTrainingIndicesResponse>(
trainee.id,
"get_session_training_indices",
request,
);
return { payload: response.payload, warnings: response.warnings };
}

Expand Down
39 changes: 33 additions & 6 deletions src/engine/Trainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Trainee implements BaseTrainee {
protected _name: BaseTrainee["name"];
protected _persistence: BaseTrainee["persistence"];
protected _metadata: BaseTrainee["metadata"];
protected _deleted = false;

constructor(client: AbstractBaseClient, obj: BaseTrainee) {
this.client = client;
Expand All @@ -38,6 +39,38 @@ export class Trainee implements BaseTrainee {
return this._metadata || {};
}

public get isDeleted(): boolean {
return this._deleted;
}

public async update(properties: Partial<BaseTrainee>): Promise<void> {
const trainee = await this.client.updateTrainee({ ...properties, id: this.id });
this._name = trainee.name;
this._metadata = trainee.metadata;
this._persistence = trainee.persistence;
}

public async delete(): Promise<void> {
await this.client.deleteTrainee(this.id);
this._deleted = true;
}

public async copy(name?: string): Promise<Trainee> {
return await this.client.copyTrainee(this.id, name);
}

public async acquireResources(): Promise<void> {
return await this.client.acquireTraineeResources(this.id);
}

public async releaseResources(): Promise<void> {
return await this.client.releaseTraineeResources(this.id);
}

public async persist(): Promise<void> {
await this.client.persistTrainee(this.id);
}

/**
* Train data into the Trainee using batched requests to the Engine.
* @param traineeId The Trainee identifier.
Expand Down Expand Up @@ -244,12 +277,6 @@ export class Trainee implements BaseTrainee {

/**
* Returns an assoc with case distances, containing a list of case session indices and a list of lists (matrix) of the computed distances.
* in the following format:
* {
* 'column_case_indices' : [ session-indices ],
* 'row_case_indices' : [ session-indices ],
* 'distances': [ [ pairwise distances ] ]
* }
* @param traineeId The Trainee identifier.
* @param request The operation parameters.
* @returns The response of the operation, including any warnings.
Expand Down
11 changes: 11 additions & 0 deletions src/types/schemas/CreateSubtrainee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ export type CreateSubtraineeRequest = {
*/
trainee_id?: string;
};

export type CreateSubtraineeResponse = {
/**
* The ID of the resulting trainee that was created.
*/
id?: string;
/**
* The name of the resulting trainee that was created.
*/
name?: string;
};
Loading

0 comments on commit 582bec9

Please sign in to comment.