Skip to content

Commit

Permalink
Removes @tinacms/search from tinacms
Browse files Browse the repository at this point in the history
We're doing this because the `@tinacms/search` package uses `sqlite-level`, which in turn depends on the `better-sqlite3` package that is breaking the builds on Build Cloud / Ripple CI: teambit/bit#8628
  • Loading branch information
coreyaus committed Mar 15, 2024
1 parent cb074db commit 2277d63
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 206 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-eagles-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tinacms': patch
---

Removes the @tinacms/search dependency from tinacms given that uses sqlite-level, which in turn depends on the better-sqlite3 package that is breaking the builds on Build Cloud / Ripple CI: https://github.com/teambit/bit/issues/8628
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.17.0
16.14.2
3 changes: 1 addition & 2 deletions packages/tinacms/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tinacms",
"version": "1.6.0",
"name": "tinacms",
"main": "dist/index.js",
"module": "./dist/index.mjs",
"exports": {
Expand Down Expand Up @@ -76,7 +76,6 @@
"@react-types/shared": "^3.10.0",
"@sambego/storybook-styles": "^1.0.0",
"@tinacms/schema-tools": "workspace:*",
"@tinacms/search": "workspace:*",
"@tinacms/mdx": "workspace:*",
"@tinacms/sharedctx": "workspace:*",
"@udecode/plate-headless": "^21.4.0",
Expand Down
91 changes: 46 additions & 45 deletions packages/tinacms/src/admin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type { Collection, TinaSchema } from '@tinacms/schema-tools'
import type { Client } from '../internalClient'
import type { CollectionResponse, DocumentForm } from './types'

import {
SearchClient,
processDocumentForIndexing,
} from '@tinacms/search/dist/index-client'
// import {
// SearchClient,
// processDocumentForIndexing,
// } from '@tinacms/search/dist/index-client'

export interface FilterArgs {
filterField: string
Expand All @@ -24,7 +24,8 @@ export class TinaAdminApi {
api: Client
useDataLayer: boolean
schema: TinaSchema
searchClient?: SearchClient
// searchClient?: SearchClient
searchClient?: any
maxSearchIndexFieldLength: number = 100
constructor(cms: TinaCMS) {
this.api = cms.api.tina
Expand Down Expand Up @@ -67,20 +68,20 @@ export class TinaAdminApi {
{ variables: { collection, relativePath, newRelativePath } }
)

if (this.searchClient) {
const { document: doc } = await this.fetchDocument(
collection.name,
newRelativePath
)
const processed = processDocumentForIndexing(
doc['_values'],
`${collection.path}/${newRelativePath}`,
collection,
this.maxSearchIndexFieldLength
)
await this.searchClient.put([processed])
await this.searchClient.del([`${collection.name}:${relativePath}`])
}
// if (this.searchClient) {
// const { document: doc } = await this.fetchDocument(
// collection.name,
// newRelativePath
// )
// const processed = processDocumentForIndexing(
// doc['_values'],
// `${collection.path}/${newRelativePath}`,
// collection,
// this.maxSearchIndexFieldLength
// )
// await this.searchClient.put([processed])
// await this.searchClient.del([`${collection.name}:${relativePath}`])
// }
}

async deleteDocument({
Expand Down Expand Up @@ -340,19 +341,19 @@ export class TinaAdminApi {
}
)

if (this.searchClient) {
const { document: doc } = await this.fetchDocument(
collection.name,
relativePath
)
const processed = processDocumentForIndexing(
doc['_values'],
`${collection.path}/${relativePath}`,
collection,
this.maxSearchIndexFieldLength
)
await this.searchClient.put([processed])
}
// if (this.searchClient) {
// const { document: doc } = await this.fetchDocument(
// collection.name,
// relativePath
// )
// const processed = processDocumentForIndexing(
// doc['_values'],
// `${collection.path}/${relativePath}`,
// collection,
// this.maxSearchIndexFieldLength
// )
// await this.searchClient.put([processed])
// }

return response
}
Expand Down Expand Up @@ -380,19 +381,19 @@ export class TinaAdminApi {
}
)

if (this.searchClient) {
const { document: doc } = await this.fetchDocument(
collection.name,
relativePath
)
const processed = processDocumentForIndexing(
doc['_values'],
`${collection.path}/${relativePath}`,
collection,
this.maxSearchIndexFieldLength
)
await this.searchClient.put([processed])
}
// if (this.searchClient) {
// const { document: doc } = await this.fetchDocument(
// collection.name,
// relativePath
// )
// const processed = processDocumentForIndexing(
// doc['_values'],
// `${collection.path}/${relativePath}`,
// collection,
// this.maxSearchIndexFieldLength
// )
// await this.searchClient.put([processed])
// }

return response
}
Expand Down
108 changes: 55 additions & 53 deletions packages/tinacms/src/internalClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
AuthProvider,
} from '@tinacms/schema-tools'
import { TinaCloudProject } from './types'
import {
optionsToSearchIndexOptions,
parseSearchIndexResponse,
queryToSearchIndexQuery,
SearchClient,
} from '@tinacms/search/dist/index-client'
// import {
// optionsToSearchIndexOptions,
// parseSearchIndexResponse,
// queryToSearchIndexQuery,
// SearchClient,
// } from '@tinacms/search/dist/index-client'
import { AsyncData, asyncPoll } from './asyncPoll'
import { LocalAuthProvider, TinaCloudAuthProvider } from './authProvider'

Expand Down Expand Up @@ -583,36 +583,37 @@ export class LocalClient extends Client {
}
}

export class TinaCMSSearchClient implements SearchClient {
// export class TinaCMSSearchClient implements SearchClient {
export class TinaCMSSearchClient {
constructor(
private client: Client,
private tinaSearchConfig?: { stopwordLanguages?: string[] }
) {}
async query(
query: string,
options?: {
limit?: number
cursor?: string
}
): Promise<{
results: any[]
nextCursor: string | null
total: number
prevCursor: string | null
}> {
const q = queryToSearchIndexQuery(
query,
this.tinaSearchConfig?.stopwordLanguages
)
const opt = optionsToSearchIndexOptions(options)
const optionsParam = opt['PAGE'] ? `&options=${JSON.stringify(opt)}` : ''
const res = await this.client.authProvider.fetchWithToken(
`${this.client.contentApiBase}/searchIndex/${
this.client.clientId
}/${this.client.getBranch()}?q=${JSON.stringify(q)}${optionsParam}`
)
return parseSearchIndexResponse(await res.json(), options)
}
// async query(
// query: string,
// options?: {
// limit?: number
// cursor?: string
// }
// ): Promise<{
// results: any[]
// nextCursor: string | null
// total: number
// prevCursor: string | null
// }> {
// const q = queryToSearchIndexQuery(
// query,
// this.tinaSearchConfig?.stopwordLanguages
// )
// const opt = optionsToSearchIndexOptions(options)
// const optionsParam = opt['PAGE'] ? `&options=${JSON.stringify(opt)}` : ''
// const res = await this.client.authProvider.fetchWithToken(
// `${this.client.contentApiBase}/searchIndex/${
// this.client.clientId
// }/${this.client.getBranch()}?q=${JSON.stringify(q)}${optionsParam}`
// )
// return parseSearchIndexResponse(await res.json(), options)
// }

async del(ids: string[]): Promise<any> {
const res = await this.client.authProvider.fetchWithToken(
Expand Down Expand Up @@ -652,28 +653,29 @@ export class TinaCMSSearchClient implements SearchClient {
}
}

export class LocalSearchClient implements SearchClient {
// export class LocalSearchClient implements SearchClient {
export class LocalSearchClient {
constructor(private client: Client) {}
async query(
query: string,
options?: {
limit?: number
cursor?: string
}
): Promise<{
results: any[]
nextCursor: string | null
total: number
prevCursor: string | null
}> {
const q = queryToSearchIndexQuery(query)
const opt = optionsToSearchIndexOptions(options)
const optionsParam = opt['PAGE'] ? `&options=${JSON.stringify(opt)}` : ''
const res = await this.client.authProvider.fetchWithToken(
`http:https://localhost:4001/searchIndex?q=${JSON.stringify(q)}${optionsParam}`
)
return parseSearchIndexResponse(await res.json(), options)
}
// async query(
// query: string,
// options?: {
// limit?: number
// cursor?: string
// }
// ): Promise<{
// results: any[]
// nextCursor: string | null
// total: number
// prevCursor: string | null
// }> {
// const q = queryToSearchIndexQuery(query)
// const opt = optionsToSearchIndexOptions(options)
// const optionsParam = opt['PAGE'] ? `&options=${JSON.stringify(opt)}` : ''
// const res = await this.client.authProvider.fetchWithToken(
// `http:https://localhost:4001/searchIndex?q=${JSON.stringify(q)}${optionsParam}`
// )
// return parseSearchIndexResponse(await res.json(), options)
// }

del(ids: string[]): Promise<any> {
return Promise.resolve(undefined)
Expand Down
Loading

0 comments on commit 2277d63

Please sign in to comment.