fase(3): crawling module domain and application
This commit is contained in:
24
dist/modules/crawling/domain/value-objects/Url.js
vendored
Normal file
24
dist/modules/crawling/domain/value-objects/Url.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Url = void 0;
|
||||
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
class Url extends ValueObject_1.ValueObject {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
static create(raw) {
|
||||
if (!raw || raw.trim().length === 0) {
|
||||
return (0, Result_1.Err)('URL must not be empty');
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed.startsWith('http://') && !trimmed.startsWith('https://')) {
|
||||
return (0, Result_1.Err)('URL must start with http:// or https://');
|
||||
}
|
||||
return (0, Result_1.Ok)(new Url({ value: trimmed }));
|
||||
}
|
||||
toString() {
|
||||
return this.props.value;
|
||||
}
|
||||
}
|
||||
exports.Url = Url;
|
||||
Reference in New Issue
Block a user