locals: handle ignored properties, ignore ModelRelation.model
This commit is contained in:
parent
eb6ed8f2d2
commit
a85d899a21
@ -3,7 +3,7 @@ import ModelFactory from "./ModelFactory.js";
|
|||||||
import ModelQuery, {ModelFieldData, ModelQueryResult, WhereTest} from "./ModelQuery.js";
|
import ModelQuery, {ModelFieldData, ModelQueryResult, WhereTest} from "./ModelQuery.js";
|
||||||
|
|
||||||
export default abstract class ModelRelation<S extends Model, O extends Model, R extends O | O[] | null> {
|
export default abstract class ModelRelation<S extends Model, O extends Model, R extends O | O[] | null> {
|
||||||
protected readonly model: S;
|
protected readonly _model: S;
|
||||||
protected readonly foreignModelType: ModelType<O>;
|
protected readonly foreignModelType: ModelType<O>;
|
||||||
protected readonly dbProperties: RelationDatabaseProperties;
|
protected readonly dbProperties: RelationDatabaseProperties;
|
||||||
protected readonly queryModifiers: QueryModifier<O>[] = [];
|
protected readonly queryModifiers: QueryModifier<O>[] = [];
|
||||||
@ -11,7 +11,7 @@ export default abstract class ModelRelation<S extends Model, O extends Model, R
|
|||||||
protected cachedModels?: O[];
|
protected cachedModels?: O[];
|
||||||
|
|
||||||
protected constructor(model: S, foreignModelType: ModelType<O>, dbProperties: RelationDatabaseProperties) {
|
protected constructor(model: S, foreignModelType: ModelType<O>, dbProperties: RelationDatabaseProperties) {
|
||||||
this.model = model;
|
this._model = model;
|
||||||
this.foreignModelType = foreignModelType;
|
this.foreignModelType = foreignModelType;
|
||||||
this.dbProperties = dbProperties;
|
this.dbProperties = dbProperties;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ export default abstract class ModelRelation<S extends Model, O extends Model, R
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getModelId(): ModelFieldData {
|
public getModelId(): ModelFieldData {
|
||||||
return this.model[this.dbProperties.localKey];
|
return this._model[this.dbProperties.localKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected applyRegularConstraints(query: ModelQuery<O>): void {
|
protected applyRegularConstraints(query: ModelQuery<O>): void {
|
||||||
@ -111,7 +111,7 @@ export class OneModelRelation<S extends Model, O extends Model> extends ModelRel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public clone(): OneModelRelation<S, O> {
|
public clone(): OneModelRelation<S, O> {
|
||||||
return new OneModelRelation(this.model, this.foreignModelType, this.dbProperties);
|
return new OneModelRelation(this._model, this.foreignModelType, this.dbProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected collectionToOutput(models: O[]): O | null {
|
protected collectionToOutput(models: O[]): O | null {
|
||||||
@ -119,11 +119,11 @@ export class OneModelRelation<S extends Model, O extends Model> extends ModelRel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async set(model: O): Promise<void> {
|
public async set(model: O): Promise<void> {
|
||||||
(this.model as Model)[this.dbProperties.localKey] = model[this.dbProperties.foreignKey];
|
(this._model as Model)[this.dbProperties.localKey] = model[this.dbProperties.foreignKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async clear(): Promise<void> {
|
public async clear(): Promise<void> {
|
||||||
(this.model as Model)[this.dbProperties.localKey] = undefined;
|
(this._model as Model)[this.dbProperties.localKey] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,11 +139,11 @@ export class ManyModelRelation<S extends Model, O extends Model> extends ModelRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public clone(): ManyModelRelation<S, O> {
|
public clone(): ManyModelRelation<S, O> {
|
||||||
return new ManyModelRelation<S, O>(this.model, this.foreignModelType, this.dbProperties);
|
return new ManyModelRelation<S, O>(this._model, this.foreignModelType, this.dbProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cloneReduceToOne(): OneModelRelation<S, O> {
|
public cloneReduceToOne(): OneModelRelation<S, O> {
|
||||||
return new OneModelRelation<S, O>(this.model, this.foreignModelType, this.dbProperties);
|
return new OneModelRelation<S, O>(this._model, this.foreignModelType, this.dbProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected collectionToOutput(models: O[]): O[] {
|
protected collectionToOutput(models: O[]): O[] {
|
||||||
@ -178,7 +178,7 @@ export class ManyThroughModelRelation<S extends Model, O extends Model> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public clone(): ManyThroughModelRelation<S, O> {
|
public clone(): ManyThroughModelRelation<S, O> {
|
||||||
return new ManyThroughModelRelation<S, O>(this.model, this.foreignModelType, this.dbProperties);
|
return new ManyThroughModelRelation<S, O>(this._model, this.foreignModelType, this.dbProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cloneReduceToOne(): OneModelRelation<S, O> {
|
public cloneReduceToOne(): OneModelRelation<S, O> {
|
||||||
@ -229,7 +229,7 @@ export class RecursiveModelRelation<M extends Model> extends ManyModelRelation<M
|
|||||||
}
|
}
|
||||||
|
|
||||||
public clone(): RecursiveModelRelation<M> {
|
public clone(): RecursiveModelRelation<M> {
|
||||||
return new RecursiveModelRelation(this.model, this.foreignModelType, this.dbProperties);
|
return new RecursiveModelRelation(this._model, this.foreignModelType, this.dbProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async populate(models: ModelQueryResult<M>): Promise<void> {
|
public async populate(models: ModelQueryResult<M>): Promise<void> {
|
||||||
|
@ -76,6 +76,7 @@ export default class SvelteViewEngine extends ViewEngine {
|
|||||||
|
|
||||||
const localMap: Record<string, unknown> = this.compileBackendCalls(backendCalls.split('\n'), locals, false);
|
const localMap: Record<string, unknown> = this.compileBackendCalls(backendCalls.split('\n'), locals, false);
|
||||||
const actualLocals = JSON.stringify(localMap, (key, value) => {
|
const actualLocals = JSON.stringify(localMap, (key, value) => {
|
||||||
|
if (key.startsWith('_')) return undefined;
|
||||||
return typeof value === 'function' ?
|
return typeof value === 'function' ?
|
||||||
value.toString() :
|
value.toString() :
|
||||||
value;
|
value;
|
||||||
|
Loading…
Reference in New Issue
Block a user