Add svelte as a view engine to swaf #33
@ -3,7 +3,7 @@ import ModelFactory from "./ModelFactory.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> {
|
||||
protected readonly model: S;
|
||||
protected readonly _model: S;
|
||||
protected readonly foreignModelType: ModelType<O>;
|
||||
protected readonly dbProperties: RelationDatabaseProperties;
|
||||
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 constructor(model: S, foreignModelType: ModelType<O>, dbProperties: RelationDatabaseProperties) {
|
||||
this.model = model;
|
||||
this._model = model;
|
||||
this.foreignModelType = foreignModelType;
|
||||
this.dbProperties = dbProperties;
|
||||
}
|
||||
@ -35,7 +35,7 @@ export default abstract class ModelRelation<S extends Model, O extends Model, R
|
||||
}
|
||||
|
||||
public getModelId(): ModelFieldData {
|
||||
return this.model[this.dbProperties.localKey];
|
||||
return this._model[this.dbProperties.localKey];
|
||||
}
|
||||
|
||||
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> {
|
||||
return new OneModelRelation(this.model, this.foreignModelType, this.dbProperties);
|
||||
return new OneModelRelation(this._model, this.foreignModelType, this.dbProperties);
|
||||
}
|
||||
|
||||
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> {
|
||||
(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> {
|
||||
(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> {
|
||||
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> {
|
||||
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[] {
|
||||
@ -178,7 +178,7 @@ export class ManyThroughModelRelation<S extends Model, O extends Model> extends
|
||||
}
|
||||
|
||||
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> {
|
||||
@ -229,7 +229,7 @@ export class RecursiveModelRelation<M extends Model> extends ManyModelRelation<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> {
|
||||
|
@ -76,6 +76,7 @@ export default class SvelteViewEngine extends ViewEngine {
|
||||
|
||||
const localMap: Record<string, unknown> = this.compileBackendCalls(backendCalls.split('\n'), locals, false);
|
||||
const actualLocals = JSON.stringify(localMap, (key, value) => {
|
||||
if (key.startsWith('_')) return undefined;
|
||||
return typeof value === 'function' ?
|
||||
value.toString() :
|
||||
value;
|
||||
|
Loading…
Reference in New Issue
Block a user