mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): typing for logging context
This commit is contained in:
parent
e873b69850
commit
051e88ca90
@ -1,9 +1,8 @@
|
||||
import type { JSONObject } from 'common/types';
|
||||
import { rgbaColorToString } from 'common/util/colorCodeTransformers';
|
||||
import { deepClone } from 'common/util/deepClone';
|
||||
import type { CanvasLayer } from 'features/controlLayers/konva/CanvasLayer';
|
||||
import type { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
import type { EraserLine } from 'features/controlLayers/store/types';
|
||||
import type { EraserLine, GetLoggingContext } from 'features/controlLayers/store/types';
|
||||
import { RGBA_RED } from 'features/controlLayers/store/types';
|
||||
import Konva from 'konva';
|
||||
import type { Logger } from 'roarr';
|
||||
@ -17,7 +16,7 @@ export class CanvasEraserLine {
|
||||
parent: CanvasLayer;
|
||||
manager: CanvasManager;
|
||||
log: Logger;
|
||||
getLoggingContext: (extra?: JSONObject) => JSONObject;
|
||||
getLoggingContext: GetLoggingContext;
|
||||
|
||||
state: EraserLine;
|
||||
konva: {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import type { JSONObject } from 'common/types';
|
||||
import { deepClone } from 'common/util/deepClone';
|
||||
import type { CanvasLayer } from 'features/controlLayers/konva/CanvasLayer';
|
||||
import type { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
import type { CanvasStagingArea } from 'features/controlLayers/konva/CanvasStagingArea';
|
||||
import { FILTER_MAP } from 'features/controlLayers/konva/filters';
|
||||
import { loadImage } from 'features/controlLayers/konva/util';
|
||||
import type { ImageObject } from 'features/controlLayers/store/types';
|
||||
import type { GetLoggingContext, ImageObject } from 'features/controlLayers/store/types';
|
||||
import { t } from 'i18next';
|
||||
import Konva from 'konva';
|
||||
import type { Logger } from 'roarr';
|
||||
@ -19,10 +19,10 @@ export class CanvasImage {
|
||||
static PLACEHOLDER_TEXT_NAME = `${CanvasImage.TYPE}_placeholder-text`;
|
||||
|
||||
id: string;
|
||||
parent: CanvasLayer;
|
||||
parent: CanvasLayer | CanvasStagingArea;
|
||||
manager: CanvasManager;
|
||||
log: Logger;
|
||||
getLoggingContext: (extra?: JSONObject) => JSONObject;
|
||||
getLoggingContext: GetLoggingContext;
|
||||
|
||||
state: ImageObject;
|
||||
konva: {
|
||||
@ -34,7 +34,7 @@ export class CanvasImage {
|
||||
isLoading: boolean;
|
||||
isError: boolean;
|
||||
|
||||
constructor(state: ImageObject, parent: CanvasLayer) {
|
||||
constructor(state: ImageObject, parent: CanvasLayer | CanvasStagingArea) {
|
||||
const { id, width, height, x, y } = state;
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { JSONObject } from 'common/types';
|
||||
import type { CanvasLayer } from 'features/controlLayers/konva/CanvasLayer';
|
||||
import type { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
import { getPrefixedId } from 'features/controlLayers/konva/util';
|
||||
import type { GetLoggingContext } from 'features/controlLayers/store/types';
|
||||
import Konva from 'konva';
|
||||
import type { Logger } from 'roarr';
|
||||
|
||||
@ -12,7 +12,7 @@ export class CanvasInteractionRect {
|
||||
parent: CanvasLayer;
|
||||
manager: CanvasManager;
|
||||
log: Logger;
|
||||
getLoggingContext: (extra?: JSONObject) => JSONObject;
|
||||
getLoggingContext: GetLoggingContext;
|
||||
|
||||
konva: {
|
||||
rect: Konva.Rect;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { getStore } from 'app/store/nanostores/store';
|
||||
import { deepClone } from 'common/util/deepClone';
|
||||
import { CanvasBrushLine } from 'features/controlLayers/konva/CanvasBrushLine';
|
||||
import { CanvasEntity } from 'features/controlLayers/konva/CanvasEntity';
|
||||
import { CanvasEraserLine } from 'features/controlLayers/konva/CanvasEraserLine';
|
||||
import { CanvasImage } from 'features/controlLayers/konva/CanvasImage';
|
||||
import { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
@ -9,22 +8,24 @@ import { CanvasRect } from 'features/controlLayers/konva/CanvasRect';
|
||||
import { CanvasTransformer } from 'features/controlLayers/konva/CanvasTransformer';
|
||||
import { getPrefixedId, konvaNodeToBlob, mapId, previewBlob } from 'features/controlLayers/konva/util';
|
||||
import { layerRasterized } from 'features/controlLayers/store/canvasV2Slice';
|
||||
import {
|
||||
type BrushLine,
|
||||
type CanvasV2State,
|
||||
type Coordinate,
|
||||
type EraserLine,
|
||||
imageDTOToImageObject,
|
||||
type LayerEntity,
|
||||
type Rect,
|
||||
type RectShape,
|
||||
import type {
|
||||
BrushLine,
|
||||
CanvasV2State,
|
||||
Coordinate,
|
||||
EraserLine,
|
||||
GetLoggingContext,
|
||||
LayerEntity,
|
||||
Rect,
|
||||
RectShape,
|
||||
} from 'features/controlLayers/store/types';
|
||||
import { imageDTOToImageObject } from 'features/controlLayers/store/types';
|
||||
import Konva from 'konva';
|
||||
import { debounce, get } from 'lodash-es';
|
||||
import type { Logger } from 'roarr';
|
||||
import { uploadImage } from 'services/api/endpoints/images';
|
||||
import { assert } from 'tsafe';
|
||||
|
||||
export class CanvasLayer extends CanvasEntity {
|
||||
export class CanvasLayer {
|
||||
static TYPE = 'layer';
|
||||
static LAYER_NAME = `${CanvasLayer.TYPE}_layer`;
|
||||
static TRANSFORMER_NAME = `${CanvasLayer.TYPE}_transformer`;
|
||||
@ -33,6 +34,11 @@ export class CanvasLayer extends CanvasEntity {
|
||||
static OBJECT_GROUP_NAME = `${CanvasLayer.TYPE}_object-group`;
|
||||
static BBOX_NAME = `${CanvasLayer.TYPE}_bbox`;
|
||||
|
||||
id: string;
|
||||
manager: CanvasManager;
|
||||
log: Logger;
|
||||
getLoggingContext: GetLoggingContext;
|
||||
|
||||
drawingBuffer: BrushLine | EraserLine | RectShape | null;
|
||||
state: LayerEntity;
|
||||
|
||||
@ -54,7 +60,10 @@ export class CanvasLayer extends CanvasEntity {
|
||||
bbox: Rect;
|
||||
|
||||
constructor(state: LayerEntity, manager: CanvasManager) {
|
||||
super(state.id, manager);
|
||||
this.id = state.id;
|
||||
this.manager = manager;
|
||||
this.getLoggingContext = this.manager.buildEntityGetLoggingContext(this);
|
||||
this.log = this.manager.buildLogger(this.getLoggingContext);
|
||||
this.log.debug({ state }, 'Creating layer');
|
||||
|
||||
this.konva = {
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
} from 'features/controlLayers/konva/util';
|
||||
import type { Extents, ExtentsResult, GetBboxTask, WorkerLogMessage } from 'features/controlLayers/konva/worker';
|
||||
import { $lastProgressEvent, $shouldShowStagedImage } from 'features/controlLayers/store/canvasV2Slice';
|
||||
import type { CanvasV2State, Coordinate, GenerationMode } from 'features/controlLayers/store/types';
|
||||
import type { CanvasV2State, Coordinate, GenerationMode, GetLoggingContext } from 'features/controlLayers/store/types';
|
||||
import type Konva from 'konva';
|
||||
import { atom } from 'nanostores';
|
||||
import type { Logger } from 'roarr';
|
||||
@ -595,7 +595,7 @@ export class CanvasManager {
|
||||
|
||||
buildObjectGetLoggingContext = (
|
||||
instance: CanvasBrushLine | CanvasEraserLine | CanvasRect | CanvasImage | CanvasTransformer | CanvasInteractionRect
|
||||
) => {
|
||||
): GetLoggingContext => {
|
||||
return (extra?: JSONObject): JSONObject => {
|
||||
return {
|
||||
...instance.parent.getLoggingContext(),
|
||||
@ -605,7 +605,7 @@ export class CanvasManager {
|
||||
};
|
||||
};
|
||||
|
||||
buildEntityGetLoggingContext = (instance: CanvasLayer) => {
|
||||
buildEntityGetLoggingContext = (instance: CanvasLayer | CanvasStagingArea): GetLoggingContext => {
|
||||
return (extra?: JSONObject): JSONObject => {
|
||||
return {
|
||||
...instance.manager.getLoggingContext(),
|
||||
|
@ -1,9 +1,8 @@
|
||||
import type { JSONObject } from 'common/types';
|
||||
import { rgbaColorToString } from 'common/util/colorCodeTransformers';
|
||||
import { deepClone } from 'common/util/deepClone';
|
||||
import type { CanvasLayer } from 'features/controlLayers/konva/CanvasLayer';
|
||||
import type { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
import type { RectShape } from 'features/controlLayers/store/types';
|
||||
import type { GetLoggingContext, RectShape } from 'features/controlLayers/store/types';
|
||||
import Konva from 'konva';
|
||||
import type { Logger } from 'roarr';
|
||||
|
||||
@ -16,7 +15,7 @@ export class CanvasRect {
|
||||
parent: CanvasLayer;
|
||||
manager: CanvasManager;
|
||||
log: Logger;
|
||||
getLoggingContext: (extra?: JSONObject) => JSONObject;
|
||||
getLoggingContext: GetLoggingContext;
|
||||
|
||||
state: RectShape;
|
||||
konva: {
|
||||
|
@ -1,8 +1,7 @@
|
||||
import type { JSONObject } from 'common/types';
|
||||
import type { CanvasLayer } from 'features/controlLayers/konva/CanvasLayer';
|
||||
import type { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
import { getPrefixedId } from 'features/controlLayers/konva/util';
|
||||
import type { Coordinate } from 'features/controlLayers/store/types';
|
||||
import type { Coordinate , GetLoggingContext } from 'features/controlLayers/store/types';
|
||||
import Konva from 'konva';
|
||||
import type { Logger } from 'roarr';
|
||||
|
||||
@ -10,10 +9,10 @@ export class CanvasTransformer {
|
||||
static TYPE = 'transformer';
|
||||
|
||||
id: string;
|
||||
parent: CanvasLayer;
|
||||
parent: CanvasLayer
|
||||
manager: CanvasManager;
|
||||
log: Logger;
|
||||
getLoggingContext: (extra?: JSONObject) => JSONObject;
|
||||
getLoggingContext: GetLoggingContext
|
||||
|
||||
isActive: boolean;
|
||||
konva: {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import type { JSONObject } from 'common/types';
|
||||
import type { CanvasControlAdapter } from 'features/controlLayers/konva/CanvasControlAdapter';
|
||||
import { CanvasInpaintMask } from 'features/controlLayers/konva/CanvasInpaintMask';
|
||||
import { CanvasLayer } from 'features/controlLayers/konva/CanvasLayer';
|
||||
@ -963,3 +964,5 @@ export function isDrawableEntityType(
|
||||
): entityType is 'layer' | 'regional_guidance' | 'inpaint_mask' {
|
||||
return entityType === 'layer' || entityType === 'regional_guidance' || entityType === 'inpaint_mask';
|
||||
}
|
||||
|
||||
export type GetLoggingContext = (extra?: JSONObject) => JSONObject;
|
||||
|
Loading…
x
Reference in New Issue
Block a user