@mayder/devibe 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -2
- package/bin/devibe.mjs +7 -0
- package/dist/cli.js +50 -0
- package/dist/diff.js +61 -0
- package/dist/graphify.js +141 -0
- package/dist/highlight.LICENSE +29 -0
- package/dist/highlight.min.js +1262 -0
- package/dist/model.js +64 -0
- package/dist/server.js +100 -0
- package/dist/source.js +87 -0
- package/dist/support-desk.js +80 -0
- package/dist/viewer.html +731 -0
- package/examples/support-desk/after/route.ts +14 -0
- package/examples/support-desk/after/ticket-service.ts +11 -0
- package/examples/support-desk/before/route.ts +11 -0
- package/examples/support-desk/before/ticket-service.ts +7 -0
- package/package.json +28 -4
package/dist/model.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { createServer } from 'node:http'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const uiPath = new URL('../../../work/atlas-review.html', import.meta.url)
|
|
7
|
+
const developmentHighlighterPath = new URL('../node_modules/@highlightjs/cdn-assets/highlight.min.js', import.meta.url)
|
|
8
|
+
|
|
9
|
+
export function renderPage(atlasCase , markup ) {
|
|
10
|
+
const data = JSON.stringify(atlasCase).replaceAll('<', '\\u003c')
|
|
11
|
+
return `<!doctype html>
|
|
12
|
+
<html lang="es">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8">
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
16
|
+
<title>DeVibe</title>
|
|
17
|
+
<link rel="icon" href="data:,">
|
|
18
|
+
<style>
|
|
19
|
+
:root { color-scheme: light dark; }
|
|
20
|
+
:root[data-devibe-theme="light"] { color-scheme: light; }
|
|
21
|
+
:root[data-devibe-theme="dark"] { color-scheme: dark; }
|
|
22
|
+
body { margin: 0; padding: clamp(8px, 2.5vw, 32px); background: light-dark(#eff4db, #141815); }
|
|
23
|
+
#atlas-review { max-width: 1160px; margin: 0 auto; }
|
|
24
|
+
#atlas-review i[data-lucide] { display: inline-grid; place-items: center; font-style: normal; }
|
|
25
|
+
#atlas-review i[data-lucide="route"]::before { content: '↳'; }
|
|
26
|
+
#atlas-review i[data-lucide="hard-drive"]::before { content: '▣'; }
|
|
27
|
+
#atlas-review i[data-lucide="git-commit-horizontal"]::before { content: '⊙'; }
|
|
28
|
+
#atlas-review i[data-lucide="file-code-2"]::before { content: '≡'; }
|
|
29
|
+
#atlas-review i[data-lucide="panels-top-left"]::before { content: '▤'; }
|
|
30
|
+
#atlas-review i[data-lucide="arrow-right-left"]::before { content: '⇄'; }
|
|
31
|
+
#atlas-review i[data-lucide="database"]::before { content: '▱'; }
|
|
32
|
+
#atlas-review i[data-lucide="messages-square"]::before { content: '□'; }
|
|
33
|
+
#atlas-review i[data-lucide="chevron-right"]::before { content: '›'; }
|
|
34
|
+
</style>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<script id="atlas-case-data" type="application/json">${data}</script>
|
|
38
|
+
<script src="./highlight.min.js"></script>
|
|
39
|
+
${markup}
|
|
40
|
+
</body>
|
|
41
|
+
</html>`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export async function startServer(atlasCase , inspection = {}) {
|
|
50
|
+
const [viewer, highlighter] = await Promise.all([
|
|
51
|
+
readFile(new URL('./viewer.html', import.meta.url), 'utf8').catch(error => {
|
|
52
|
+
if (error.code !== 'ENOENT') throw error
|
|
53
|
+
return readFile(uiPath, 'utf8')
|
|
54
|
+
}),
|
|
55
|
+
readFile(new URL('./highlight.min.js', import.meta.url)).catch(error => {
|
|
56
|
+
if (error.code !== 'ENOENT') throw error
|
|
57
|
+
return readFile(developmentHighlighterPath)
|
|
58
|
+
}),
|
|
59
|
+
])
|
|
60
|
+
const page = renderPage(atlasCase, viewer)
|
|
61
|
+
const json = JSON.stringify(atlasCase)
|
|
62
|
+
const server = createServer(async (request, response) => {
|
|
63
|
+
response.setHeader('Cache-Control', 'no-store')
|
|
64
|
+
response.setHeader('Content-Security-Policy', "default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'; base-uri 'none'; frame-ancestors 'none'")
|
|
65
|
+
const sendJson = (code , body ) => response.writeHead(code, { 'Content-Type': 'application/json; charset=utf-8' }).end(JSON.stringify(body))
|
|
66
|
+
const target = new URL(`http://127.0.0.1${request.url?.startsWith('/') ? request.url : '/'}`)
|
|
67
|
+
if (request.method !== 'GET') {
|
|
68
|
+
response.writeHead(405, { Allow: 'GET' }).end()
|
|
69
|
+
} else if (target.pathname === '/') {
|
|
70
|
+
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }).end(page)
|
|
71
|
+
} else if (target.pathname === '/highlight.min.js') {
|
|
72
|
+
response.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8' }).end(highlighter)
|
|
73
|
+
} else if (target.pathname === '/api/case') {
|
|
74
|
+
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' }).end(json)
|
|
75
|
+
} else if (target.pathname === '/api/flow' || target.pathname === '/api/patch') {
|
|
76
|
+
try {
|
|
77
|
+
const result = target.pathname === '/api/flow'
|
|
78
|
+
? await inspection.flow?.(target.searchParams.get('entry') ?? '')
|
|
79
|
+
: await inspection.patch?.(target.searchParams.get('file') ?? '')
|
|
80
|
+
if (result) sendJson(200, result)
|
|
81
|
+
else sendJson(404, { error: 'Esta selección no está disponible.' })
|
|
82
|
+
} catch {
|
|
83
|
+
sendJson(500, { error: 'DeVibe no pudo leer esta selección. Vuelve a abrir el repositorio y prueba otra vez.' })
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
response.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' }).end('Ruta no disponible')
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
await new Promise ((resolve, reject) => {
|
|
91
|
+
server.once('error', reject)
|
|
92
|
+
server.listen(0, '127.0.0.1', () => {
|
|
93
|
+
server.off('error', reject)
|
|
94
|
+
resolve()
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
const address = server.address()
|
|
98
|
+
if (!address || typeof address === 'string') throw new Error('No se pudo resolver la URL local de DeVibe.')
|
|
99
|
+
return { server, url: `http://127.0.0.1:${address.port}` }
|
|
100
|
+
}
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process'
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import { promisify } from 'node:util'
|
|
5
|
+
|
|
6
|
+
import { parseChangedFiles, parsePatch } from './diff.js'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const exec = promisify(execFile)
|
|
10
|
+
|
|
11
|
+
export function excerpt(file , source , focus , start = focus, end = focus) {
|
|
12
|
+
const lines = source.replace(/\r?\n$/, '').split(/\r?\n/)
|
|
13
|
+
if (start < 1 || start > focus || focus > end || end > lines.length) {
|
|
14
|
+
throw new Error(`No se encontró la referencia ${file}:${focus} en el rango ${start}–${end}.`)
|
|
15
|
+
}
|
|
16
|
+
return { file, start, focus, lines: lines.slice(start - 1, end) }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function readExample(snapshot , file ) {
|
|
20
|
+
return readFile(new URL(`../examples/support-desk/${snapshot}/${file}`, import.meta.url), 'utf8')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class LocalGitSource {
|
|
24
|
+
root
|
|
25
|
+
|
|
26
|
+
constructor(path ) {
|
|
27
|
+
this.root = resolve(path)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async #git(...args ) {
|
|
31
|
+
try {
|
|
32
|
+
const { stdout } = await exec('git', args, {
|
|
33
|
+
cwd: this.root,
|
|
34
|
+
encoding: 'utf8',
|
|
35
|
+
maxBuffer: 3 * 1024 * 1024,
|
|
36
|
+
windowsHide: true,
|
|
37
|
+
})
|
|
38
|
+
return stdout
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
throw new Error(`Git no pudo ejecutar ${args[0]} en ${this.root}. ${cause instanceof Error ? cause.message : ''}`, { cause })
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async resolve(ref ) {
|
|
45
|
+
const sha = (await this.#git('rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`)).trim()
|
|
46
|
+
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(sha)) throw new Error(`Revisión Git inválida: ${ref}`)
|
|
47
|
+
return sha
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
readFile(commit , file ) {
|
|
51
|
+
return this.#git('show', '--no-ext-diff', '--no-textconv', `${commit}:${file}`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async topLevel() {
|
|
55
|
+
return (await this.#git('rev-parse', '--show-toplevel')).trim()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async comparison(base , head ) {
|
|
59
|
+
const revisions = head ? [base, head] : [base]
|
|
60
|
+
const diffFlags = ['--no-ext-diff', '--no-textconv', '--no-color', '--find-renames']
|
|
61
|
+
const files = parseChangedFiles(await this.#git('diff', ...diffFlags, '--name-status', '-z', ...revisions, '--'))
|
|
62
|
+
if (!head) {
|
|
63
|
+
const untracked = (await this.#git('ls-files', '--others', '--exclude-standard', '-z')).split('\0').filter(Boolean)
|
|
64
|
+
for (const path of untracked) files.push({ status: '?', path })
|
|
65
|
+
}
|
|
66
|
+
const entries = new Map(files.map(file => [file.path, file]))
|
|
67
|
+
const snapshots = new Map ()
|
|
68
|
+
const read = (path ) => {
|
|
69
|
+
const file = entries.get(path)
|
|
70
|
+
if (!file) return undefined
|
|
71
|
+
if (file.status === '?') return Promise.resolve({ file, hunks: [], summary: ['Archivo sin seguimiento. Git todavía no lo incluye en el diff.'] })
|
|
72
|
+
let pending = snapshots.get(path)
|
|
73
|
+
if (!pending) {
|
|
74
|
+
pending = this.#patch(diffFlags, revisions, file)
|
|
75
|
+
snapshots.set(path, pending)
|
|
76
|
+
}
|
|
77
|
+
return pending
|
|
78
|
+
}
|
|
79
|
+
return { files, read }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async #patch(flags , revisions , file ) {
|
|
83
|
+
const paths = file.previous ? [file.previous, file.path] : [file.path]
|
|
84
|
+
const output = await this.#git('--literal-pathspecs', 'diff', ...flags, '--patch', '--unified=3', ...revisions, '--', ...paths)
|
|
85
|
+
return parsePatch(file, output)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
import { excerpt, readExample } from './source.js'
|
|
3
|
+
|
|
4
|
+
export async function supportDesk() {
|
|
5
|
+
const [beforeRoute, afterRoute, beforeService, afterService] = await Promise.all([
|
|
6
|
+
readExample('before', 'route.ts'),
|
|
7
|
+
readExample('after', 'route.ts'),
|
|
8
|
+
readExample('before', 'ticket-service.ts'),
|
|
9
|
+
readExample('after', 'ticket-service.ts'),
|
|
10
|
+
])
|
|
11
|
+
|
|
12
|
+
const flow = [
|
|
13
|
+
{
|
|
14
|
+
title: 'Recibir el ticket', symbol: 'POST /tickets', icon: 'panels-top-left', change: 'Misma entrada',
|
|
15
|
+
explanation: 'La ruta lee el JSON y requiere un título de tipo texto.',
|
|
16
|
+
effect: 'La comprobación inicial del tipo se conserva.',
|
|
17
|
+
before: excerpt('route.ts', beforeRoute, 4, 3, 7), after: excerpt('route.ts', afterRoute, 4, 3, 7),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: 'Validar el título', symbol: 'createTicket(title, store)', icon: 'arrow-right-left', change: 'Validación nueva',
|
|
21
|
+
explanation: 'La ruta llama al servicio. El servicio rechaza títulos vacíos o formados solo por espacios.',
|
|
22
|
+
effect: 'Antes el servicio pasaba directamente al escritor. Ahora comprueba el título antes de hacerlo.',
|
|
23
|
+
before: excerpt('ticket-service.ts', beforeService, 6, 5, 7), after: excerpt('ticket-service.ts', afterService, 6, 5, 10),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
title: 'Guardar el ticket', symbol: 'TicketStore.insert(title)', icon: 'database', change: 'Escritura condicionada',
|
|
27
|
+
explanation: 'El servicio llama a la interfaz de almacenamiento cuando el título supera la validación.',
|
|
28
|
+
effect: 'La llamada a insert sigue presente. El retorno anticipado evita que se ejecute con un título en blanco.',
|
|
29
|
+
before: excerpt('ticket-service.ts', beforeService, 6, 5, 7), after: excerpt('ticket-service.ts', afterService, 10, 5, 11),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: 'Responder con el ticket', symbol: 'Response.json(ticket, { status: 201 })', icon: 'messages-square', change: 'Nueva respuesta de error',
|
|
33
|
+
explanation: 'La ruta devuelve 201 con el ticket creado. Si el servicio devuelve null, devuelve 422.',
|
|
34
|
+
effect: 'Un título válido conserva la respuesta 201. Un título en blanco ahora recibe 422.',
|
|
35
|
+
before: excerpt('route.ts', beforeRoute, 10, 9, 10), after: excerpt('route.ts', afterRoute, 13, 9, 13),
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
const error = {
|
|
39
|
+
title: 'Rechazar el título vacío',
|
|
40
|
+
explanation: 'La validación devuelve null antes de insertar. La ruta responde con 422.',
|
|
41
|
+
effect: 'El mismo cuerpo antes llegaba al escritor y devolvía 201.',
|
|
42
|
+
before: excerpt('route.ts', beforeRoute, 10, 9, 10), after: excerpt('route.ts', afterRoute, 11, 9, 13),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
project: 'Support Desk', area: 'Tickets', title: 'Crear un ticket', environment: 'demo',
|
|
47
|
+
summary: 'Sigue la solicitud desde la ruta hasta la escritura y su respuesta.', base: 'antes', head: 'después',
|
|
48
|
+
diff: {
|
|
49
|
+
title: 'Validar antes de guardar',
|
|
50
|
+
explanation: 'Un título de solo espacios pasa de guardarse con 201 a recibir 422 sin escritura.',
|
|
51
|
+
files: [['route.ts', beforeRoute, afterRoute], ['ticket-service.ts', beforeService, afterService]]
|
|
52
|
+
.filter(([, before, after]) => before !== after).map(([file]) => file),
|
|
53
|
+
},
|
|
54
|
+
review: {
|
|
55
|
+
title: 'SD-01 · Rechazar tickets con título vacío', description: 'Ticket de ejemplo',
|
|
56
|
+
criteria: [{ id: 'reject', label: 'Devuelve 422', step: 4 }, { id: 'storage', label: 'Protege la escritura', step: 2 }],
|
|
57
|
+
},
|
|
58
|
+
labels: { request: 'POST', database: 'Escribe', response: 'Ver respuesta HTTP' },
|
|
59
|
+
places: {
|
|
60
|
+
web: { title: 'Entrada', role: 'Ruta HTTP', change: 'Misma entrada' },
|
|
61
|
+
api: { title: 'Servicio', role: 'Tickets', change: 'Validación' },
|
|
62
|
+
data: { title: 'Escritura', role: 'Almacenamiento', change: 'Condicionada' },
|
|
63
|
+
error: { title: '422', role: 'Título vacío', change: 'Rechazo' },
|
|
64
|
+
},
|
|
65
|
+
flow,
|
|
66
|
+
error,
|
|
67
|
+
details: {
|
|
68
|
+
symbol: [
|
|
69
|
+
{ id: 'route', label: 'postTicket', kind: 'Función', layer: 'web', step: 0, item: flow[0] },
|
|
70
|
+
{ id: 'service', label: 'createTicket', kind: 'Función', layer: 'api', step: 1, item: flow[1] },
|
|
71
|
+
{ id: 'store', label: 'TicketStore', kind: 'Interfaz', layer: 'data', step: 2, item: flow[2] },
|
|
72
|
+
],
|
|
73
|
+
call: [
|
|
74
|
+
{ id: 'json', label: 'request.json()', kind: 'Llamada a un método', layer: 'web', step: 0, item: flow[0] },
|
|
75
|
+
{ id: 'create', label: 'createTicket()', kind: 'Llamada', layer: 'api', step: 1, item: flow[1] },
|
|
76
|
+
{ id: 'insert', label: 'store.insert()', kind: 'Llamada a un método', layer: 'data', step: 2, item: flow[2] },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|