mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
refactor(editor): rename job to transformer (#9639)
This commit is contained in:
@@ -2,7 +2,7 @@ import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
||||
|
||||
import type { DraftModel, Store } from '../model/index.js';
|
||||
import type { AssetsManager } from '../transformer/assets.js';
|
||||
import type { Job, Slice } from '../transformer/index.js';
|
||||
import type { Slice, Transformer } from '../transformer/index.js';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
@@ -62,13 +62,13 @@ export function wrapFakeNote(snapshot: SliceSnapshot) {
|
||||
}
|
||||
|
||||
export abstract class BaseAdapter<AdapterTarget = unknown> {
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
|
||||
get configs() {
|
||||
return this.job.adapterConfigs;
|
||||
}
|
||||
|
||||
constructor(job: Job) {
|
||||
constructor(job: Transformer) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
|
||||
import type { BlobCRUD } from './type.js';
|
||||
import type { BlobCRUD } from './type';
|
||||
|
||||
type AssetsManagerConfig = {
|
||||
blob: BlobCRUD;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { BlockModel } from '../model/block/block-model.js';
|
||||
import type { DraftModel } from '../model/block/draft.js';
|
||||
import type { BlockModel } from '../model/block/block-model';
|
||||
import type { DraftModel } from '../model/block/draft';
|
||||
import {
|
||||
type InternalPrimitives,
|
||||
internalPrimitives,
|
||||
} from '../model/block/zod.js';
|
||||
import type { AssetsManager } from './assets.js';
|
||||
import { fromJSON, toJSON } from './json.js';
|
||||
import type { BlockSnapshot } from './type.js';
|
||||
} from '../model/block/zod';
|
||||
import type { AssetsManager } from './assets';
|
||||
import { fromJSON, toJSON } from './json';
|
||||
import type { BlockSnapshot } from './type';
|
||||
|
||||
export type BlockSnapshotLeaf = Pick<
|
||||
BlockSnapshot,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * from './assets.js';
|
||||
export * from './base.js';
|
||||
export * from './job.js';
|
||||
export * from './json.js';
|
||||
export * from './middleware.js';
|
||||
export * from './slice.js';
|
||||
export * from './type.js';
|
||||
export * from './assets';
|
||||
export * from './base';
|
||||
export * from './json';
|
||||
export * from './middleware';
|
||||
export * from './slice';
|
||||
export * from './transformer';
|
||||
export * from './type';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NATIVE_UNIQ_IDENTIFIER, TEXT_UNIQ_IDENTIFIER } from '../consts.js';
|
||||
import { Boxed } from '../reactive/boxed.js';
|
||||
import { isPureObject } from '../reactive/index.js';
|
||||
import { Text } from '../reactive/text.js';
|
||||
import { NATIVE_UNIQ_IDENTIFIER, TEXT_UNIQ_IDENTIFIER } from '../consts';
|
||||
import { Boxed } from '../reactive/boxed';
|
||||
import { isPureObject } from '../reactive/index';
|
||||
import { Text } from '../reactive/text';
|
||||
|
||||
export function toJSON(value: unknown): unknown {
|
||||
if (value instanceof Boxed) {
|
||||
|
||||
@@ -71,18 +71,20 @@ export type FinalPayload =
|
||||
type: 'info';
|
||||
};
|
||||
|
||||
export type JobSlots = {
|
||||
export type TransformerSlots = {
|
||||
beforeImport: Slot<BeforeImportPayload>;
|
||||
afterImport: Slot<FinalPayload>;
|
||||
beforeExport: Slot<BeforeExportPayload>;
|
||||
afterExport: Slot<FinalPayload>;
|
||||
};
|
||||
|
||||
type JobMiddlewareOptions = {
|
||||
type TransformerMiddlewareOptions = {
|
||||
assetsManager: AssetsManager;
|
||||
slots: JobSlots;
|
||||
slots: TransformerSlots;
|
||||
docCRUD: DocCRUD;
|
||||
adapterConfigs: Map<string, string>;
|
||||
};
|
||||
|
||||
export type JobMiddleware = (options: JobMiddlewareOptions) => void;
|
||||
export type TransformerMiddleware = (
|
||||
options: TransformerMiddlewareOptions
|
||||
) => void;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { DraftModel, Store } from '../model/index.js';
|
||||
import type { DraftModel, Store } from '../model/index';
|
||||
|
||||
type SliceData = {
|
||||
content: DraftModel[];
|
||||
|
||||
@@ -14,8 +14,8 @@ import type {
|
||||
BeforeExportPayload,
|
||||
BeforeImportPayload,
|
||||
FinalPayload,
|
||||
JobMiddleware,
|
||||
JobSlots,
|
||||
TransformerMiddleware,
|
||||
TransformerSlots,
|
||||
} from './middleware.js';
|
||||
import { Slice } from './slice.js';
|
||||
import type {
|
||||
@@ -31,11 +31,11 @@ import {
|
||||
SliceSnapshotSchema,
|
||||
} from './type.js';
|
||||
|
||||
export type JobConfig = {
|
||||
export type TransformerOptions = {
|
||||
schema: Schema;
|
||||
blobCRUD: BlobCRUD;
|
||||
docCRUD: DocCRUD;
|
||||
middlewares?: JobMiddleware[];
|
||||
middlewares?: TransformerMiddleware[];
|
||||
};
|
||||
|
||||
interface FlatSnapshot {
|
||||
@@ -53,7 +53,7 @@ interface DraftBlockTreeNode {
|
||||
// The number of blocks to insert in one batch
|
||||
const BATCH_SIZE = 100;
|
||||
|
||||
export class Job {
|
||||
export class Transformer {
|
||||
private readonly _adapterConfigs = new Map<string, string>();
|
||||
|
||||
private readonly _assetsManager: AssetsManager;
|
||||
@@ -62,7 +62,7 @@ export class Job {
|
||||
|
||||
private readonly _docCRUD: DocCRUD;
|
||||
|
||||
private readonly _slots: JobSlots = {
|
||||
private readonly _slots: TransformerSlots = {
|
||||
beforeImport: new Slot<BeforeImportPayload>(),
|
||||
afterImport: new Slot<FinalPayload>(),
|
||||
beforeExport: new Slot<BeforeExportPayload>(),
|
||||
@@ -338,7 +338,12 @@ export class Job {
|
||||
return this._docCRUD;
|
||||
}
|
||||
|
||||
constructor({ blobCRUD, schema, docCRUD, middlewares = [] }: JobConfig) {
|
||||
constructor({
|
||||
blobCRUD,
|
||||
schema,
|
||||
docCRUD,
|
||||
middlewares = [],
|
||||
}: TransformerOptions) {
|
||||
this._assetsManager = new AssetsManager({ blob: blobCRUD });
|
||||
this._schema = schema;
|
||||
this._docCRUD = docCRUD;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { Store } from '../model/store/store.js';
|
||||
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta.js';
|
||||
import type { Store } from '../model/store/store';
|
||||
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta';
|
||||
|
||||
export type BlockSnapshot = {
|
||||
type: 'block';
|
||||
|
||||
Reference in New Issue
Block a user