Skip to content

Commit a5e76f3

Browse files
chore: wip
1 parent 53dd1d2 commit a5e76f3

File tree

10 files changed

+433
-29
lines changed

10 files changed

+433
-29
lines changed

.stacks/core/actions/src/generate/model-classes.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,4 @@ export class UserModel {
296296
}
297297
}
298298

299-
const UserInstance = new UserModel()
300-
301-
const user = await UserInstance.find(1)
302-
303-
const res = await user.update({ name: 'glenn 2' })
304-
305-
console.log(res)
306299
process.exit(0)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { path as p } from '@stacksjs/path'
2+
3+
const modelGenerate = Bun.file('model-classes.ts') // Assuming Bun is imported properly
4+
const file = Bun.file(p.projectStoragePath('framework/orm/UserModel.ts'))
5+
6+
const code = await modelGenerate.text()
7+
8+
const writer = file.writer()
9+
10+
writer.write(code)
11+
12+
await writer.end()

.stacks/core/desktop/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
],
5252
"scripts": {
5353
"build": "bun --bun build.ts",
54-
"build:app": "vite build ../../../../storage/framework/desktop/music -c ../../core/vite/src/music.ts",
55-
"dev": "bun --bun vite serve ../../../storage/framework/desktop/music -c ../../core/vite/src/music.ts",
54+
"build:app": "vite build ../../../../storage/framework/desktop/dashboard -c ../../core/vite/src/desktop.ts",
55+
"dev": "bun --bun vite serve ../../../storage/framework/desktop/dashboard -c ../../core/vite/src/desktop.ts",
5656
"dev:app": "tauri dev",
5757
"typecheck": "bun --bun tsc --noEmit",
5858
"prepublishOnly": "bun --bun run build"

.stacks/core/search-engine/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@stacksjs/ui": "workspace:*"
5858
},
5959
"dependencies": {
60+
"@opensearch-project/opensearch": "^2.4.0",
6061
"meilisearch": "^0.35.0"
6162
},
6263
"devDependencies": {

.stacks/core/search-engine/src/drivers/meilisearch.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { searchEngine } from '@stacksjs/config'
22
import { log } from '@stacksjs/logging'
33
import type { MeiliSearchOptions, SearchEngineDriver } from '@stacksjs/types'
44
import { ExitCode } from '@stacksjs/types'
5-
import type { SearchResponse } from 'meilisearch'
5+
import type { DocumentOptions, DocumentsDeletionQuery, DocumentsIds, EnqueuedTask, Index, IndexOptions, IndexesResults, SearchResponse } from 'meilisearch'
66
import { MeiliSearch } from 'meilisearch'
77
import process from 'node:process'
88

@@ -34,6 +34,50 @@ async function search(index: string, params: any): Promise<SearchResponse<Record
3434
.search(params.query, { limit: params.perPage, filter, sort, offset: offsetVal })
3535
}
3636

37+
async function addDocument(indexName:string, params: any): Promise<EnqueuedTask> {
38+
return await client().index(indexName).addDocuments([params])
39+
}
40+
41+
async function addDocuments(indexName:string, params: any[]): Promise<EnqueuedTask> {
42+
return await client().index(indexName).addDocuments(params)
43+
}
44+
45+
async function createIndex(name: string, options?: IndexOptions): Promise<EnqueuedTask> {
46+
return await client().createIndex(name, options)
47+
}
48+
49+
async function updateIndex(indexName: string, params: IndexOptions): Promise<EnqueuedTask> {
50+
return await client().updateIndex(indexName, params)
51+
}
52+
53+
async function updateDocument(indexName: string, params: DocumentOptions): Promise<EnqueuedTask> {
54+
return await client().index(indexName).updateDocuments([params])
55+
}
56+
57+
async function updateDocuments(indexName: string, params: DocumentOptions[]): Promise<EnqueuedTask> {
58+
return await client().index(indexName).updateDocuments(params)
59+
}
60+
61+
async function deleteDocument(indexName: string, id: number): Promise<EnqueuedTask> {
62+
return await client().index(indexName).deleteDocument(id)
63+
}
64+
65+
async function deleteDocuments(indexName: string, filters: string | string[]): Promise<EnqueuedTask> {
66+
return await client().index(indexName).deleteDocuments({ filter: filters })
67+
}
68+
69+
async function getDocument(indexName: string, id: number, fields: any): Promise<EnqueuedTask> {
70+
return await client().index(indexName).getDocument(id, fields)
71+
}
72+
73+
async function deleteIndex(indexName: string): Promise<EnqueuedTask> {
74+
return await client().deleteIndex(indexName)
75+
}
76+
77+
async function listAllIndexes(): Promise<IndexesResults<Index[]>> {
78+
return await client().getIndexes()
79+
}
80+
3781
function convertToMeilisearchFilter(jsonData: any): string[] {
3882
const filters: string[] = [];
3983

@@ -66,5 +110,16 @@ function convertToMeilisearchSorting(jsonData: any): string[] {
66110
export default {
67111
client,
68112
search,
69-
// ...other methods
113+
createIndex,
114+
deleteIndex,
115+
updateIndex,
116+
listAllIndexes,
117+
addDocument,
118+
addDocuments,
119+
updateDocument
120+
listAllIndices: listAllIndexes,
121+
updateDocuments,
122+
deleteDocument,
123+
deleteDocuments,
124+
getDocument
70125
} satisfies SearchEngineDriver
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { searchEngine } from '@stacksjs/config'
2+
import { ApiResponse, Client } from "@opensearch-project/opensearch";
3+
import type { SearchEngineDriver } from '@stacksjs/types'
4+
5+
const host = searchEngine.openSearch?.host
6+
const protocol = searchEngine.openSearch?.protocol
7+
const port = searchEngine.openSearch?.port
8+
const auth = searchEngine.openSearch?.auth
9+
10+
const client = new Client({
11+
node: `${protocol}://${auth}@${host}:${port}`,
12+
});
13+
14+
async function search(index: string, params?: any) {
15+
const response = await client.search({
16+
index,
17+
body: params.query,
18+
});
19+
20+
return response
21+
}
22+
23+
async function createIndex(indexName: string, settings?: any): Promise<ApiResponse<any, any>> {
24+
return await client.indices.create({ index: indexName, body: settings })
25+
}
26+
// async function updateIndex(indexName: string, settings?: any): Promise<ApiResponse<any, any>> {
27+
// return await client.indices.update({ index: indexName, body: settings })
28+
// }
29+
30+
async function deleteIndex(indexName: string): Promise<ApiResponse<any, any>> {
31+
return await client.indices.delete({ index: indexName })
32+
}
33+
34+
async function addDocument(indexName: string, document: any): Promise<ApiResponse<any, any>> {
35+
return await client.index({
36+
id: document.id,
37+
index: indexName,
38+
body: document,
39+
refresh: true,
40+
})
41+
}
42+
43+
async function deleteDocument(indexName: string, document: any): Promise<ApiResponse<any, any>> {
44+
return await client.delete({
45+
id: document.id,
46+
index: indexName,
47+
})
48+
}
49+
50+
export default {
51+
client,
52+
search,
53+
createIndex,
54+
deleteIndex,
55+
addDocument,
56+
deleteDocument
57+
// ...other methods
58+
} satisfies SearchEngineDriver
59+

.stacks/core/types/src/search-engine.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ export interface SearchEngineOptions {
2222
* @default string 'meilisearch'
2323
* @see https://stacksjs.org/docs/search-engine
2424
*/
25-
driver: 'meilisearch' | 'algolia'
25+
driver: 'meilisearch' | 'algolia' | 'opensearch'
2626

2727
meilisearch?: {
2828
host: string
2929
apiKey: string
3030
}
3131

32+
openSearch?: {
33+
host: string
34+
protocol: number
35+
port: number
36+
auth: string,
37+
}
38+
3239
filters?: {
3340
[key: string]: string
3441
}

.stacks/stacks/dashboard/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"typecheck": "bun --bun tsc --noEmit"
4343
},
4444
"devDependencies": {
45+
"@stacksjs/config": "workspace:*",
4546
"@stacksjs/development": "workspace:*"
4647
}
4748
}

.stacks/stacks/dashboard/src/pages/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script setup lang="ts">
22
import Alert from '../components/Modals/Popups/Alert.vue'
33
import BaseModal from '../components/Modals/BaseModal.vue'
4+
5+
import { useSearchEngine } from '@stacksjs/search-engine'
6+
7+
console.log(useSearchEngine)
48
</script>
59

610
<template>

0 commit comments

Comments
 (0)