Skip to content

Commit c04c23a

Browse files
Refactored styleguide ingestion logic by introducing StyleguideModel for improved structure and type safety. Replaced the previous Styleguides type with a Record type for better clarity. Removed the obsolete styleguides.types.ts file and updated related functions to accommodate these changes.
1 parent b860bc1 commit c04c23a

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

ingestion/src/lib/models/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ export interface EmbeddingsContainer {
1616
contentEmbeddings?: number[]
1717
}
1818

19-
export type NodeDescriptor = "Node" | "Documentation" | "Code"
19+
export type NodeDescriptor = "Node" | "Documentation" | "Code" | "Styleguide"
20+
21+
export * from "./code"
22+
export * from "./devdoc"
23+
export * from "./styleguide"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { BaseNode, BaseRelation, EmbeddingsContainer, NodeDescriptor } from "."
2+
3+
export type Styleguides = Record<string, string>
4+
export type StyleguideModelRelation = BaseRelation
5+
6+
export interface StyleguideModelProps extends BaseNode, EmbeddingsContainer {
7+
name: string
8+
filePath: string
9+
content: string
10+
descriptor: NodeDescriptor
11+
}
12+
13+
export class StyleguideModel implements StyleguideModelProps {
14+
id: string
15+
name: string
16+
filePath: string
17+
content: string
18+
relations: StyleguideModelRelation[]
19+
nameEmbeddings: number[]
20+
codeEmbeddings: number[]
21+
contentEmbeddings: number[]
22+
descriptor: NodeDescriptor
23+
24+
constructor(props: StyleguideModelProps) {
25+
this.id = props.id
26+
this.name = props.name
27+
this.filePath = props.filePath
28+
this.content = props.content
29+
this.relations = props.relations
30+
this.nameEmbeddings = props.nameEmbeddings || []
31+
this.codeEmbeddings = props.codeEmbeddings || []
32+
this.contentEmbeddings = props.contentEmbeddings || []
33+
this.descriptor = props.descriptor
34+
}
35+
36+
getDBInsertQuery(): string {
37+
return `
38+
CREATE (n:Styleguide {
39+
id: $id,
40+
name: $name,
41+
filePath: $filePath,
42+
content: $content,
43+
nameEmbeddings: $nameEmbeddings,
44+
codeEmbeddings: $codeEmbeddings,
45+
contentEmbeddings: $contentEmbeddings,
46+
descriptor: $descriptor
47+
})
48+
`
49+
}
50+
51+
getNodeName(): string {
52+
return this.name
53+
}
54+
}

ingestion/src/lib/styleguides.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { writeFileSync } from "fs"
2-
import { CodeModel } from "./models/code"
3-
import { db } from "./neo4j"
4-
import { Styleguides } from "./styleguides.types"
2+
import { StyleguideModel } from "./models/styleguide"
53

64
const links = [
75
"https://github.com/RocketChat/Rocket.Chat/raw/develop/.prettierrc",
@@ -24,7 +22,7 @@ const links = [
2422
"https://github.com/RocketChat/Rocket.Chat/raw/develop/tsconfig.base.server.json",
2523
]
2624

27-
let styleguides: Styleguides = {}
25+
let styleguides: Record<string, string> = {}
2826

2927
async function fetchStyleguide(url: string) {
3028
const res = await fetch(url)
@@ -33,7 +31,7 @@ async function fetchStyleguide(url: string) {
3331
styleguides[filePath] = data
3432
}
3533

36-
async function fetchStyleguides(): Promise<Styleguides> {
34+
async function fetchStyleguides(): Promise<Record<string, string>> {
3735
await Promise.all(links.map(fetchStyleguide))
3836
const result = { ...styleguides }
3937
styleguides = {}
@@ -54,17 +52,16 @@ export async function insertStyleguides() {
5452

5553
const jobs = []
5654
for (const [filePath, data] of Object.entries(styleguides)) {
57-
const node = new CodeModel({
55+
const node = new StyleguideModel({
5856
id: filePath,
5957
name: filePath,
60-
type: "",
61-
code: data,
6258
filePath: filePath,
59+
content: data,
6360
relations: [],
6461
nameEmbeddings: [],
6562
codeEmbeddings: [],
66-
descriptor: "Styleguide",
67-
isFile: true,
63+
contentEmbeddings: [],
64+
descriptor: "Styleguide"
6865
})
6966
const job = transaction.run(node.getDBInsertQuery(), node)
7067
jobs.push(job)

ingestion/src/lib/styleguides.types.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)