fase(3): crawling module domain and application

This commit is contained in:
debian
2026-03-04 16:32:09 -05:00
parent 4a58749048
commit 39c5313ba5
40 changed files with 1117 additions and 13 deletions

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrawlAction = void 0;
const Entity_1 = require("../../../../shared/domain/Entity");
class CrawlAction extends Entity_1.Entity {
constructor(props, id) {
super(props, id);
}
static create(props, id) {
return new CrawlAction(props, id);
}
get type() {
return this.props.type;
}
get selector() {
return this.props.selector;
}
get value() {
return this.props.value;
}
get seed() {
return this.props.seed;
}
get stateId() {
return this.props.stateId;
}
get sessionId() {
return this.props.sessionId;
}
get sequenceOrder() {
return this.props.sequenceOrder;
}
}
exports.CrawlAction = CrawlAction;

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrawlSession = void 0;
const AggregateRoot_1 = require("../../../../shared/domain/AggregateRoot");
const Result_1 = require("../../../../shared/domain/Result");
const Url_1 = require("../value-objects/Url");
const CrawlStarted_1 = require("../events/CrawlStarted");
const CrawlCompleted_1 = require("../events/CrawlCompleted");
const CrawlFailed_1 = require("../events/CrawlFailed");
class CrawlSession extends AggregateRoot_1.AggregateRoot {
constructor(props, id) {
super(props, id);
}
static create(request) {
const urlResult = Url_1.Url.create(request.url);
if (!urlResult.ok) {
return (0, Result_1.Err)(urlResult.error);
}
const props = {
url: request.url,
status: 'running',
seed: request.seed,
maxStates: request.maxStates,
statesVisited: 0,
config: request.config ?? {},
};
const session = new CrawlSession(props);
session.addDomainEvent(new CrawlStarted_1.CrawlStarted(session.id.toString(), {
url: request.url,
seed: request.seed,
maxStates: request.maxStates,
}));
return (0, Result_1.Ok)(session);
}
get url() {
return this.props.url;
}
get status() {
return this.props.status;
}
get seed() {
return this.props.seed;
}
get maxStates() {
return this.props.maxStates;
}
get statesVisited() {
return this.props.statesVisited;
}
get config() {
return this.props.config;
}
incrementStatesVisited() {
this.props = { ...this.props, statesVisited: this.props.statesVisited + 1 };
}
complete() {
this.props = { ...this.props, status: 'completed' };
this.addDomainEvent(new CrawlCompleted_1.CrawlCompleted(this.id.toString(), {
url: this.props.url,
statesVisited: this.props.statesVisited,
}));
}
fail(reason) {
this.props = { ...this.props, status: 'failed' };
this.addDomainEvent(new CrawlFailed_1.CrawlFailed(this.id.toString(), {
url: this.props.url,
reason,
statesVisited: this.props.statesVisited,
}));
}
stop() {
this.props = { ...this.props, status: 'stopped' };
this.addDomainEvent(new CrawlCompleted_1.CrawlCompleted(this.id.toString(), {
url: this.props.url,
statesVisited: this.props.statesVisited,
stopped: true,
}));
}
}
exports.CrawlSession = CrawlSession;

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrawlState = void 0;
const Entity_1 = require("../../../../shared/domain/Entity");
class CrawlState extends Entity_1.Entity {
constructor(props, id) {
super(props, id);
}
static create(props, id) {
return new CrawlState(props, id);
}
get url() {
return this.props.url;
}
get title() {
return this.props.title;
}
get domSnapshot() {
return this.props.domSnapshot;
}
get visitCount() {
return this.props.visitCount;
}
get stateId() {
return this.props.stateId;
}
get sessionId() {
return this.props.sessionId;
}
}
exports.CrawlState = CrawlState;