Skip to content

Commit c7f6a77

Browse files
chore: wip
1 parent 4113376 commit c7f6a77

File tree

10 files changed

+136
-63
lines changed

10 files changed

+136
-63
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import process from 'node:process'
2+
import { log } from '@stacksjs/logging'
3+
import { createStripeProduct } from '@stacksjs/payments'
4+
5+
const result = await createStripeProduct()
6+
7+
if (result?.isErr()) {
8+
console.error(result.error)
9+
log.error('generateMigrations failed', result.error)
10+
process.exit(1)
11+
}

storage/framework/core/buddy/src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async function main() {
6868
cmd.release(buddy)
6969
cmd.route(buddy)
7070
cmd.saas(buddy)
71+
cmd.search(buddy)
7172
cmd.seed(buddy)
7273
cmd.setup(buddy)
7374
cmd.test(buddy)

storage/framework/core/buddy/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export * from './projects'
2525
export * from './release'
2626
export * from './route'
2727
export * from './saas'
28+
export * from './search'
2829
export * from './seed'
2930
export * from './setup'
3031
export * from './test'

storage/framework/core/buddy/src/commands/saas.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import { ExitCode } from '@stacksjs/types'
88
export function saas(buddy: CLI): void {
99
const descriptions = {
1010
stripe: 'Sets up stripe products in the dashboard',
11-
project: 'Target a specific project',
1211
verbose: 'Enable verbose output',
1312
}
1413

1514
buddy
1615
.command('stripe:setup', descriptions.stripe)
17-
.option('-p, --project [project]', descriptions.project, { default: false })
1816
.option('--verbose', descriptions.verbose, { default: false })
1917
.action(async (options: SaasOptions) => {
2018
log.debug('Running `buddy stripe:setup` ...', options)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { CLI, SearchOptions } from '@stacksjs/types'
2+
import process from 'node:process'
3+
import { runAction } from '@stacksjs/actions'
4+
import { intro, log, outro } from '@stacksjs/cli'
5+
import { Action } from '@stacksjs/enums'
6+
import { ExitCode } from '@stacksjs/types'
7+
8+
export function search(buddy: CLI): void {
9+
const descriptions = {
10+
search: 'Indexes database data to search engine',
11+
model: 'Target a specific model',
12+
verbose: 'Enable verbose output',
13+
}
14+
15+
buddy
16+
.command('search-engine:update', descriptions.search)
17+
.option('-m, --model [model]', descriptions.model, { default: false })
18+
.option('--verbose', descriptions.verbose, { default: false })
19+
.action(async (options: SearchOptions) => {
20+
log.debug('Running `search-engine:update` ...', options)
21+
22+
const perf = await intro('search-engine:update')
23+
const result = await runAction(Action.SearchEngineUpdate, options)
24+
25+
if (result.isErr()) {
26+
await outro(
27+
'While running the stripe:setup command, there was an issue',
28+
{ startTime: perf, useSeconds: true },
29+
result.error,
30+
)
31+
process.exit()
32+
}
33+
34+
await outro(`Stripe products created successfully`, {
35+
startTime: perf,
36+
useSeconds: true,
37+
})
38+
39+
process.exit(ExitCode.Success)
40+
})
41+
}

storage/framework/core/enums/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export enum Action {
8787
Release = 'release', // ✅
8888
RouteList = 'route/list', // ✅
8989
StripeSetup = 'saas/setup',
90+
SearchEngineUpdate = 'search/update',
9091
Test = 'test/index',
9192
TestUi = 'test/ui',
9293
TestUnit = 'test/unit',

storage/framework/core/payments/src/billable/setup-products.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { saas } from '@stacksjs/config'
2+
import { Err, Ok, ok } from '@stacksjs/error-handling'
23
import { log } from '@stacksjs/logging'
34
import { stripe } from '@stacksjs/payments'
45

@@ -11,7 +12,7 @@ interface PriceParams {
1112
interval: 'day' | 'month' | 'week' | 'year'
1213
}
1314
}
14-
export async function createStripeProduct(): Promise<void> {
15+
export async function createStripeProduct(): Promise<Ok<string, never> | Err<string, any>> {
1516
const plans = saas.plans
1617
try {
1718
if (plans !== undefined && plans.length) {
@@ -42,8 +43,12 @@ export async function createStripeProduct(): Promise<void> {
4243
}
4344
}
4445
}
46+
47+
return ok('Migrations generated')
4548
}
4649
catch (err: any) {
4750
log.error(err)
51+
52+
return err(err)
4853
}
4954
}
Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import type { SearchEngineDriver } from '@stacksjs/types'
1+
import { ExitCode, type MeilisearchOptions, type SearchEngineDriver } from '@stacksjs/types'
2+
import { searchEngine } from '@stacksjs/config'
23

3-
// function client(options?: MeilisearchOptions) {
4-
// let host = searchEngine.meilisearch?.host
5-
// let apiKey = searchEngine.meilisearch?.apiKey
4+
import { EnqueuedTask, Index, MeiliSearch, type DocumentOptions, type IndexesResults, type IndexOptions } from 'meilisearch'
5+
import { log } from '@stacksjs/logging'
66

7-
// if (options?.host)
8-
// host = options.host
7+
function client(): MeiliSearch {
8+
const host = searchEngine.meilisearch?.host || 'http://127.0.0.1:7700'
9+
let apiKey = searchEngine.meilisearch?.apiKey || ''
910

10-
// if (options?.apiKey)
11-
// apiKey = options.apiKey
11+
if (!host) {
12+
log.error('Please specify a search engine host.')
13+
process.exit(ExitCode.FatalError)
14+
}
1215

13-
// if (!host) {
14-
// log.error('Please specify a search engine host.')
15-
// process.exit(ExitCode.FatalError)
16-
// }
17-
18-
// return new MeiliSearch({ host, apiKey })
19-
// }
16+
return new MeiliSearch({ host, apiKey })
17+
}
2018

2119
// async function search(index: string, params: any): Promise<SearchResponse<Record<string, any>>> {
2220
// const offsetVal = ((params.page * params.perPage) - 20) || 0
@@ -28,49 +26,49 @@ import type { SearchEngineDriver } from '@stacksjs/types'
2826
// .search(params.query, { limit: params.perPage, filter, sort, offset: offsetVal })
2927
// }
3028

31-
// async function addDocument(indexName: string, params: any): Promise<EnqueuedTask> {
32-
// return await client().index(indexName).addDocuments([params])
33-
// }
29+
async function addDocument(indexName: string, params: any): Promise<EnqueuedTask> {
30+
return await client().index(indexName).addDocuments([params])
31+
}
3432

35-
// async function addDocuments(indexName: string, params: any[]): Promise<EnqueuedTask> {
36-
// return await client().index(indexName).addDocuments(params)
37-
// }
33+
async function addDocuments(indexName: string, params: any[]): Promise<EnqueuedTask> {
34+
return await client().index(indexName).addDocuments(params)
35+
}
3836

39-
// async function createIndex(name: string, options?: IndexOptions): Promise<EnqueuedTask> {
40-
// return await client().createIndex(name, options)
41-
// }
37+
async function createIndex(name: string, options?: IndexOptions): Promise<EnqueuedTask> {
38+
return await client().createIndex(name, options)
39+
}
4240

43-
// async function updateIndex(indexName: string, params: IndexOptions): Promise<EnqueuedTask> {
44-
// return await client().updateIndex(indexName, params)
45-
// }
41+
async function updateIndex(indexName: string, params: IndexOptions): Promise<EnqueuedTask> {
42+
return await client().updateIndex(indexName, params)
43+
}
4644

47-
// async function updateDocument(indexName: string, params: DocumentOptions): Promise<EnqueuedTask> {
48-
// return await client().index(indexName).updateDocuments([params])
49-
// }
45+
async function updateDocument(indexName: string, params: DocumentOptions): Promise<EnqueuedTask> {
46+
return await client().index(indexName).updateDocuments([params])
47+
}
5048

51-
// async function updateDocuments(indexName: string, params: DocumentOptions[]): Promise<EnqueuedTask> {
52-
// return await client().index(indexName).updateDocuments(params)
53-
// }
49+
async function updateDocuments(indexName: string, params: DocumentOptions[]): Promise<EnqueuedTask> {
50+
return await client().index(indexName).updateDocuments(params)
51+
}
5452

55-
// async function deleteDocument(indexName: string, id: number): Promise<EnqueuedTask> {
56-
// return await client().index(indexName).deleteDocument(id)
57-
// }
53+
async function deleteDocument(indexName: string, id: number): Promise<EnqueuedTask> {
54+
return await client().index(indexName).deleteDocument(id)
55+
}
5856

59-
// async function deleteDocuments(indexName: string, filters: string | string[]): Promise<EnqueuedTask> {
60-
// return await client().index(indexName).deleteDocuments({ filter: filters })
61-
// }
57+
async function deleteDocuments(indexName: string, filters: string | string[]): Promise<EnqueuedTask> {
58+
return await client().index(indexName).deleteDocuments({ filter: filters })
59+
}
6260

63-
// async function getDocument(indexName: string, id: number, fields: any): Promise<EnqueuedTask> {
64-
// return await client().index(indexName).getDocument(id, fields)
65-
// }
61+
async function getDocument(indexName: string, id: number, fields: any): Promise<EnqueuedTask> {
62+
return await client().index(indexName).getDocument(id, fields)
63+
}
6664

67-
// async function deleteIndex(indexName: string): Promise<EnqueuedTask> {
68-
// return await client().deleteIndex(indexName)
69-
// }
65+
async function deleteIndex(indexName: string): Promise<EnqueuedTask> {
66+
return await client().deleteIndex(indexName)
67+
}
7068

71-
// async function listAllIndexes(): Promise<IndexesResults<Index[]>> {
72-
// return await client().getIndexes()
73-
// }
69+
async function listAllIndexes(): Promise<IndexesResults<Index[]>> {
70+
return await client().getIndexes()
71+
}
7472

7573
// function convertToFilter(jsonData: any): string[] {
7674
// const filters: string[] = []
@@ -103,16 +101,16 @@ import type { SearchEngineDriver } from '@stacksjs/types'
103101
export default {
104102
client,
105103
// search,
106-
// createIndex,
107-
// deleteIndex,
108-
// updateIndex,
109-
// listAllIndexes,
110-
// addDocument,
111-
// addDocuments,
104+
createIndex,
105+
deleteIndex,
106+
updateIndex,
107+
listAllIndexes,
108+
addDocument,
109+
addDocuments,
112110
// updateDocument,
113-
// listAllIndices: listAllIndexes,
114-
// updateDocuments,
115-
// deleteDocument,
116-
// deleteDocuments,
117-
// getDocument,
111+
listAllIndices: listAllIndexes,
112+
updateDocuments,
113+
deleteDocument,
114+
deleteDocuments,
115+
getDocument,
118116
} satisfies SearchEngineDriver

storage/framework/core/types/src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ export type DomainsOptions = CliOptions & {
364364
export interface CleanOptions extends CliOptions {}
365365

366366
export interface SaasOptions extends CliOptions {}
367+
368+
export interface SearchOptions extends CliOptions {}
367369
export interface CloudCliOptions extends CliOptions {
368370
ssh?: boolean
369371
connect?: boolean

storage/framework/core/types/src/search-engine.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
DocumentOptions,
23
EnqueuedTask,
34
Hits,
45
Index,
@@ -46,6 +47,14 @@ export interface SearchEngineOptions {
4647
protocol: number
4748
port: number
4849
auth: string
50+
},
51+
52+
meilisearch?: {
53+
host: string
54+
protocol: number
55+
port: number
56+
auth: string
57+
apiKey: string
4958
}
5059

5160
filters?: {
@@ -63,11 +72,17 @@ export interface SearchEngineOptions {
6372
export type SearchEngineConfig = Partial<SearchEngineOptions>
6473

6574
export interface SearchEngineDriver {
66-
client: MeiliSearch
75+
client(): MeiliSearch
6776

6877
// Indexes
6978
createIndex: (name: string, options?: IndexOptions) => MaybePromise<EnqueuedTask>
7079
getIndex: (name: string) => MaybePromise<Index>
80+
addDocument: (indexName: string, params: any) => Promise<EnqueuedTask>
81+
updateDocuments: (indexName: string, params: DocumentOptions[]) => Promise<EnqueuedTask>
82+
addDocuments: (indexName: string, params: any[]) => Promise<EnqueuedTask>
83+
getDocument: (indexName: string, id: number, fields: any) => Promise<EnqueuedTask>
84+
deleteDocument: (indexName: string, id: number) => Promise<EnqueuedTask>
85+
deleteDocuments: (indexName: string, filters: string | string[]) => Promise<EnqueuedTask>
7186
updateIndex: (name: string, options: IndexOptions) => MaybePromise<EnqueuedTask>
7287
deleteIndex: (name: string) => MaybePromise<EnqueuedTask>
7388
updateIndexSettings: (name: string, settings: SearchEngineOptions) => MaybePromise<EnqueuedTask>

0 commit comments

Comments
 (0)