Skip to content

Commit 359bf01

Browse files
committed
chore: wip
1 parent a1ac126 commit 359bf01

File tree

5 files changed

+61
-62
lines changed

5 files changed

+61
-62
lines changed

.stacks/core/slug/src/index.ts

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
import { slug as slugify } from '@stacksjs/strings'
2-
import type { ColumnOptions, Model } from '@stacksjs/types'
3-
import { client as DatabaseClient } from '@stacksjs/database'
4-
5-
const database = new DatabaseClient()
6-
7-
export function generateSlug(model: Model, column: string, text: string): string {
8-
const field: ColumnOptions | undefined = model.columns.find((f: ColumnOptions) => f.name === column)
9-
if (!field)
10-
throw new Error(`Invalid column name: ${column}`)
11-
12-
const fieldValue = text || ''
13-
const slug = slugify(fieldValue, { lower: true })
14-
15-
if (field.unique) {
16-
let uniqueSlug = slug
17-
let count = 0
18-
while (model.records.some(record => record[column] === uniqueSlug)) {
19-
count++
20-
uniqueSlug = `${slug}-${count}`
21-
}
22-
return uniqueSlug
23-
}
24-
25-
return slug
26-
}
27-
28-
async function addSlugColumn(modelName: string, columnName: string): Promise<void> {
29-
const model = (database as any)[modelName]
30-
const fields = model._schema.fields
31-
32-
const originalField = fields.find((field: any) => field.dbName === columnName)
33-
34-
const slugField = {
35-
name: `${columnName}_slug`,
36-
type: 'String',
37-
unique: originalField.unique || false,
38-
required: originalField.required || false,
39-
default: '',
40-
}
41-
42-
await database.$executeRaw(`ALTER TABLE "${modelName}" ADD COLUMN "${columnName}_slug" VARCHAR(255)`)
43-
44-
const records = await model.findMany()
45-
46-
for (const record of records) {
47-
const originalValue = record[columnName]
48-
const slugValue = slugify(originalValue)
49-
await model.update({ where: { id: record.id }, data: { [`${columnName}_slug`]: slugValue } })
50-
}
51-
}
52-
53-
export {
54-
generateSlug as slug,
55-
}
1+
export {}
2+
// import { slug as slugify } from '@stacksjs/strings'
3+
// import type { ColumnOptions, Model } from '@stacksjs/types'
4+
// import { client as DatabaseClient } from '@stacksjs/database'
5+
6+
// const database = new DatabaseClient()
7+
8+
// export function generateSlug(model: Model, column: string, text: string): string {
9+
// const field: ColumnOptions | undefined = model.columns.find((f: ColumnOptions) => f.name === column)
10+
// if (!field)
11+
// throw new Error(`Invalid column name: ${column}`)
12+
13+
// const fieldValue = text || ''
14+
// const slug = slugify(fieldValue, { lower: true })
15+
16+
// if (field.unique) {
17+
// let uniqueSlug = slug
18+
// let count = 0
19+
// while (model.records.some(record => record[column] === uniqueSlug)) {
20+
// count++
21+
// uniqueSlug = `${slug}-${count}`
22+
// }
23+
// return uniqueSlug
24+
// }
25+
26+
// return slug
27+
// }
28+
29+
// async function addSlugColumn(modelName: string, columnName: string): Promise<void> {
30+
// const model = (database as any)[modelName]
31+
// const fields = model._schema.fields
32+
33+
// const originalField = fields.find((field: any) => field.dbName === columnName)
34+
35+
// const slugField = {
36+
// name: `${columnName}_slug`,
37+
// type: 'String',
38+
// unique: originalField.unique || false,
39+
// required: originalField.required || false,
40+
// default: '',
41+
// }
42+
43+
// await database.$executeRaw(`ALTER TABLE "${modelName}" ADD COLUMN "${columnName}_slug" VARCHAR(255)`)
44+
45+
// const records = await model.findMany()
46+
47+
// for (const record of records) {
48+
// const originalValue = record[columnName]
49+
// const slugValue = slugify(originalValue)
50+
// await model.update({ where: { id: record.id }, data: { [`${columnName}_slug`]: slugValue } })
51+
// }
52+
// }
53+
54+
// export {
55+
// generateSlug as slug,
56+
// }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import type { Options } from 'unplugin-auto-import/types'
2-
3-
export type AutoImportsOptions = Options
1+
export type { Options as AutoImportsOptions } from 'unplugin-auto-import/types'

.stacks/core/types/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export type { UserConfig as ViteConfig } from 'vite'
2-
export { type ViteSSGContext } from 'vite-ssg'
2+
export type { ViteSSGContext } from 'vite-ssg'

.stacks/core/types/src/components.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Options } from 'unplugin-vue-components'
1+
export type { Options as ComponentOptions } from 'unplugin-vue-components'
22

33
export interface TagOption {
44
/**
@@ -62,5 +62,3 @@ export interface TagOption {
6262
}
6363

6464
export type TagsOptions = TagOption[]
65-
66-
export type ComponentOptions = Options

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)