<commit_before>import * as _ from "lodash";
import * as util from "util";
import { SchemaBuilder, Overwrite } from "@serafin/schema-builder";
import { notImplementedError, serafinError } from "../error/Error";
import { final } from "./Decorator/Final";
import { IdentityInterface } from "./IdentityInterface";
import { PIPELINE, PipeAbstract } from "./PipeAbstract";
import { SchemaBuildersInterface } from "./SchemaBuildersInterface";
import { PipeInterface } from "./PipeInterface";

export type Wrapper<T, U> = { data: T[] } & U
export type PipelineMethods = "create" | "read" | "update" | "patch" | "delete";

export abstract class PipelineAbstract<M extends IdentityInterface, S extends SchemaBuildersInterface = PipelineAbstract<M, null>["defaultSchemaType"]> {
    // public relations: { [key: string]: PipelineRelation } = {};
    // public static schemaBuilderNames: SchemaBuilderNames[] = ["modelSchemaBuilder", "readQuerySchemaBuilder", "readOptionsSchemaBuilder", "readWrapperSchemaBuilder", "createValuesSchemaBuilder", "createOptionsSchemaBuilder", "createWrapperSchemaBuilder", "updateValuesSchemaBuilder", "updateOptionsSchemaBuilder", "updateWrapperSchemaBuilder", "patchQuerySchemaBuilder", "patchValuesSchemaBuilder", "patchOptionsSchemaBuilder", "patchWrapperSchemaBuilder", "deleteQuerySchemaBuilder", "deleteOptionsSchemaBuilder", "deleteWrapperSchemaBuilder"];
    public static CRUDMethods: PipelineMethods[] = ['create', 'read', 'update', 'patch', 'delete'];

    constructor(public modelSchemaBuilder: SchemaBuilder<M>, public schemaBuilders: S = null) {
        if (schemaBuilders == null) {
            this.schemaBuilders = this.defaultSchema(modelSchemaBuilder) as any;
        }

        for (let method of PipelineAbstract.CRUDMethods) {
            let thisMethod = this[`_${method}`];
            this[`_${method}`] = (...args) => {
                return (thisMethod.call(this, ...args));
            };
        }
    }

    /**
     * For 'schemaBuilder' property redefinition in an extended class. Callable through 'super.getSchemaBuilders()'.
     */
    protected getSchemaBuilders(): S {
        return this.schemaBuilders;
    }

    alterSchemaBuilders<newS extends SchemaBuildersInterface>(func: (sch: this["schemaBuilders"]) => newS) {
        this.schemaBuilders = Object.assign(this.schemaBuilders, func(this.schemaBuilders)) as any;
        return this as any as PipelineAbstract<newS["model"]["T"], Overwrite<this["schemaBuilders"], newS>>;
    }

    private defaultSchemaType = (false as true) && this.defaultSchema(null);
    private defaultSchema(modelSchemaBuilder: SchemaBuilder<M>) {
        return {
            model: modelSchemaBuilder,
            createValues: modelSchemaBuilder.clone().omitProperties(["id"]),
            createOptions: SchemaBuilder.emptySchema(),
            createWrapper: SchemaBuilder.emptySchema(),
            readQuery: modelSchemaBuilder.clone().transformPropertiesToArray().toOptionals(),
            readOptions: SchemaBuilder.emptySchema(),
            readWrapper: SchemaBuilder.emptySchema(),
            updateValues: modelSchemaBuilder.clone().omitProperties(["id"]),
            updateOptions: SchemaBuilder.emptySchema(),
            updateWrapper: SchemaBuilder.emptySchema(),
            patchQuery: modelSchemaBuilder.clone().pickProperties(["id"]).transformPropertiesToArray(),
            patchValues: modelSchemaBuilder.clone().omitProperties(["id"]).toDeepOptionals(),
            patchOptions: SchemaBuilder.emptySchema(),
            patchWrapper: SchemaBuilder.emptySchema(),
            deleteQuery: modelSchemaBuilder.pickProperties(["id"]).transformPropertiesToArray(),
            deleteOptions: SchemaBuilder.emptySchema(),<commit_msg>Create property fix<commit_after>import * as _ from "lodash";
import * as util from "util";
import { SchemaBuilder, Overwrite } from "@serafin/schema-builder";
import { notImplementedError, serafinError } from "../error/Error";
import { final } from "./Decorator/Final";
import { IdentityInterface } from "./IdentityInterface";
import { PIPELINE, PipeAbstract } from "./PipeAbstract";
import { SchemaBuildersInterface } from "./SchemaBuildersInterface";
import { PipeInterface } from "./PipeInterface";

export type Wrapper<T, U> = { data: T[] } & U
export type PipelineMethods = "create" | "read" | "update" | "patch" | "delete";

export abstract class PipelineAbstract<M extends IdentityInterface, S extends SchemaBuildersInterface = PipelineAbstract<M, null>["defaultSchemaType"]> {
    // public relations: { [key: string]: PipelineRelation } = {};
    // public static schemaBuilderNames: SchemaBuilderNames[] = ["modelSchemaBuilder", "readQuerySchemaBuilder", "readOptionsSchemaBuilder", "readWrapperSchemaBuilder", "createValuesSchemaBuilder", "createOptionsSchemaBuilder", "createWrapperSchemaBuilder", "updateValuesSchemaBuilder", "updateOptionsSchemaBuilder", "updateWrapperSchemaBuilder", "patchQuerySchemaBuilder", "patchValuesSchemaBuilder", "patchOptionsSchemaBuilder", "patchWrapperSchemaBuilder", "deleteQuerySchemaBuilder", "deleteOptionsSchemaBuilder", "deleteWrapperSchemaBuilder"];
    public static CRUDMethods: PipelineMethods[] = ['create', 'read', 'update', 'patch', 'delete'];

    constructor(public modelSchemaBuilder: SchemaBuilder<M>, public schemaBuilders: S = null) {
        if (schemaBuilders == null) {
            this.schemaBuilders = this.defaultSchema(modelSchemaBuilder) as any;
        }

        for (let method of PipelineAbstract.CRUDMethods) {
            let thisMethod = this[`_${method}`];
            this[`_${method}`] = (...args) => {
                return (thisMethod.call(this, ...args));
            };
        }
    }

    /**
     * For 'schemaBuilder' property redefinition in an extended class. Callable through 'super.getSchemaBuilders()'.
     */
    protected getSchemaBuilders(): S {
        return this.schemaBuilders;
    }

    alterSchemaBuilders<newS extends SchemaBuildersInterface>(func: (sch: this["schemaBuilders"]) => newS) {
        this.schemaBuilders = Object.assign(this.schemaBuilders, func(this.schemaBuilders)) as any;
        return this as any as PipelineAbstract<newS["model"]["T"], Overwrite<this["schemaBuilders"], newS>>;
    }

    private defaultSchemaType = (false as true) && this.defaultSchema(null);
    private defaultSchema(modelSchemaBuilder: SchemaBuilder<M>) {
        return {
            model: modelSchemaBuilder,
            createValues: modelSchemaBuilder.clone().setOptionalProperties(["id"]),
            createOptions: SchemaBuilder.emptySchema(),
            createWrapper: SchemaBuilder.emptySchema(),
            readQuery: modelSchemaBuilder.clone().transformPropertiesToArray().toOptionals(),
            readOptions: SchemaBuilder.emptySchema(),
            readWrapper: SchemaBuilder.emptySchema(),
            updateValues: modelSchemaBuilder.clone().omitProperties(["id"]),
            updateOptions: SchemaBuilder.emptySchema(),
            updateWrapper: SchemaBuilder.emptySchema(),
            patchQuery: modelSchemaBuilder.clone().pickProperties(["id"]).transformPropertiesToArray(),
            patchValues: modelSchemaBuilder.clone().omitProperties(["id"]).toDeepOptionals(),
            patchOptions: SchemaBuilder.emptySchema(),
            patchWrapper: SchemaBuilder.emptySchema(),
            deleteQuery: modelSchemaBuilder.pickProperties(["id"]).transformPropertiesToArray(),
            deleteOptions: SchemaBuilder.emptySchema(),
{'fraction_non_alphanumeric': 0.1252164646330092, 'fraction_numerical': 0.0, 'mean_word_length': 4.2175121612230715, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1775318', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1861, 'n_words': 411}