@tinacms/cli 2.0.6 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Cli, Builtins } from "clipanion";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "2.0
|
|
5
|
+
var version = "2.1.0";
|
|
6
6
|
|
|
7
7
|
// src/next/commands/dev-command/index.ts
|
|
8
8
|
import path8 from "path";
|
|
@@ -488,7 +488,15 @@ var Codegen = class {
|
|
|
488
488
|
JSON.stringify(this.graphqlSchemaDoc)
|
|
489
489
|
);
|
|
490
490
|
const { search, ...rest } = this.tinaSchema.schema.config;
|
|
491
|
-
|
|
491
|
+
if (search?.tina) {
|
|
492
|
+
const { indexerToken, ...safeSearchConfig } = search.tina;
|
|
493
|
+
this.tinaSchema.schema.config = {
|
|
494
|
+
...rest,
|
|
495
|
+
search: { tina: safeSearchConfig }
|
|
496
|
+
};
|
|
497
|
+
} else {
|
|
498
|
+
this.tinaSchema.schema.config = rest;
|
|
499
|
+
}
|
|
492
500
|
await this.writeConfigFile(
|
|
493
501
|
"_schema.json",
|
|
494
502
|
JSON.stringify(this.tinaSchema.schema)
|
|
@@ -2179,34 +2187,83 @@ var createSearchIndexRouter = ({
|
|
|
2179
2187
|
searchIndex
|
|
2180
2188
|
}) => {
|
|
2181
2189
|
const put = async (req, res) => {
|
|
2182
|
-
const
|
|
2190
|
+
const docs = req.body?.docs ?? [];
|
|
2183
2191
|
const result = await searchIndex.PUT(docs);
|
|
2184
2192
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
2185
2193
|
res.end(JSON.stringify({ result }));
|
|
2186
2194
|
};
|
|
2187
2195
|
const get = async (req, res) => {
|
|
2188
|
-
const requestURL = new URL(req.url, config2.apiURL);
|
|
2196
|
+
const requestURL = new URL(req.url ?? "", config2.apiURL);
|
|
2197
|
+
const isV2 = requestURL.pathname.startsWith("/v2/searchIndex");
|
|
2198
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
2199
|
+
if (isV2) {
|
|
2200
|
+
const queryParam = requestURL.searchParams.get("query");
|
|
2201
|
+
const collectionParam = requestURL.searchParams.get("collection");
|
|
2202
|
+
const limitParam = requestURL.searchParams.get("limit");
|
|
2203
|
+
const cursorParam = requestURL.searchParams.get("cursor");
|
|
2204
|
+
if (!queryParam) {
|
|
2205
|
+
res.end(JSON.stringify({ RESULT: [], RESULT_LENGTH: 0 }));
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
if (!searchIndex.fuzzySearchWrapper) {
|
|
2209
|
+
res.end(JSON.stringify({ RESULT: [], RESULT_LENGTH: 0 }));
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
try {
|
|
2213
|
+
const paginationOptions = {};
|
|
2214
|
+
if (limitParam) {
|
|
2215
|
+
paginationOptions.limit = parseInt(limitParam, 10);
|
|
2216
|
+
}
|
|
2217
|
+
if (cursorParam) {
|
|
2218
|
+
paginationOptions.cursor = cursorParam;
|
|
2219
|
+
}
|
|
2220
|
+
const searchQuery = collectionParam ? `${queryParam} _collection:${collectionParam}` : queryParam;
|
|
2221
|
+
const result2 = await searchIndex.fuzzySearchWrapper.query(searchQuery, {
|
|
2222
|
+
...paginationOptions
|
|
2223
|
+
});
|
|
2224
|
+
if (collectionParam) {
|
|
2225
|
+
result2.results = result2.results.filter(
|
|
2226
|
+
(r) => r._id && r._id.startsWith(`${collectionParam}:`)
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
res.end(
|
|
2230
|
+
JSON.stringify({
|
|
2231
|
+
RESULT: result2.results,
|
|
2232
|
+
RESULT_LENGTH: result2.total,
|
|
2233
|
+
NEXT_CURSOR: result2.nextCursor,
|
|
2234
|
+
PREV_CURSOR: result2.prevCursor,
|
|
2235
|
+
FUZZY_MATCHES: result2.fuzzyMatches || {}
|
|
2236
|
+
})
|
|
2237
|
+
);
|
|
2238
|
+
return;
|
|
2239
|
+
} catch (error) {
|
|
2240
|
+
console.warn(
|
|
2241
|
+
"[search] v2 fuzzy search failed:",
|
|
2242
|
+
error instanceof Error ? error.message : error
|
|
2243
|
+
);
|
|
2244
|
+
res.end(JSON.stringify({ RESULT: [], RESULT_LENGTH: 0 }));
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2189
2248
|
const query = requestURL.searchParams.get("q");
|
|
2190
2249
|
const optionsParam = requestURL.searchParams.get("options");
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2250
|
+
if (!query) {
|
|
2251
|
+
res.end(JSON.stringify({ RESULT: [] }));
|
|
2252
|
+
return;
|
|
2253
|
+
}
|
|
2254
|
+
let searchIndexOptions = { DOCUMENTS: false };
|
|
2194
2255
|
if (optionsParam) {
|
|
2195
|
-
|
|
2196
|
-
...
|
|
2256
|
+
searchIndexOptions = {
|
|
2257
|
+
...searchIndexOptions,
|
|
2197
2258
|
...JSON.parse(optionsParam)
|
|
2198
2259
|
};
|
|
2199
2260
|
}
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
res.end(JSON.stringify(result));
|
|
2204
|
-
} else {
|
|
2205
|
-
res.end(JSON.stringify({ RESULT: [] }));
|
|
2206
|
-
}
|
|
2261
|
+
const queryObj = JSON.parse(query);
|
|
2262
|
+
const result = await searchIndex.QUERY(queryObj, searchIndexOptions);
|
|
2263
|
+
res.end(JSON.stringify(result));
|
|
2207
2264
|
};
|
|
2208
2265
|
const del = async (req, res) => {
|
|
2209
|
-
const requestURL = new URL(req.url, config2.apiURL);
|
|
2266
|
+
const requestURL = new URL(req.url ?? "", config2.apiURL);
|
|
2210
2267
|
const docId = requestURL.pathname.split("/").filter(Boolean).slice(1).join("/");
|
|
2211
2268
|
const result = await searchIndex.DELETE(docId);
|
|
2212
2269
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -2296,7 +2353,7 @@ var devServerEndPointsPlugin = ({
|
|
|
2296
2353
|
res.end(JSON.stringify(result));
|
|
2297
2354
|
return;
|
|
2298
2355
|
}
|
|
2299
|
-
if (req.url.startsWith("/searchIndex")) {
|
|
2356
|
+
if (req.url.startsWith("/searchIndex") || req.url.startsWith("/v2/searchIndex")) {
|
|
2300
2357
|
if (req.method === "POST") {
|
|
2301
2358
|
await searchIndexRouter.put(req, res);
|
|
2302
2359
|
} else if (req.method === "GET") {
|
|
@@ -2577,10 +2634,14 @@ ${dangerText(e.message)}
|
|
|
2577
2634
|
configManager.config.search && searchIndexer
|
|
2578
2635
|
);
|
|
2579
2636
|
}
|
|
2637
|
+
const searchIndexWithFuzzy = searchIndexClient.searchIndex;
|
|
2638
|
+
if (searchIndexWithFuzzy && searchIndexClient.fuzzySearchWrapper) {
|
|
2639
|
+
searchIndexWithFuzzy.fuzzySearchWrapper = searchIndexClient.fuzzySearchWrapper;
|
|
2640
|
+
}
|
|
2580
2641
|
const server = await createDevServer(
|
|
2581
2642
|
configManager,
|
|
2582
2643
|
database,
|
|
2583
|
-
|
|
2644
|
+
searchIndexWithFuzzy,
|
|
2584
2645
|
apiURL,
|
|
2585
2646
|
this.noWatch,
|
|
2586
2647
|
dbLock
|
|
@@ -1,12 +1,47 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type { SearchQueryResponse, SearchResult } from '@tinacms/search';
|
|
1
3
|
export interface PathConfig {
|
|
2
4
|
apiURL: string;
|
|
3
5
|
searchPath: string;
|
|
4
6
|
}
|
|
7
|
+
interface SearchIndexOptions {
|
|
8
|
+
DOCUMENTS?: boolean;
|
|
9
|
+
PAGE?: {
|
|
10
|
+
NUMBER: number;
|
|
11
|
+
SIZE: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface SearchIndexResult {
|
|
15
|
+
RESULT: SearchResult[];
|
|
16
|
+
RESULT_LENGTH: number;
|
|
17
|
+
}
|
|
18
|
+
interface FuzzySearchWrapper {
|
|
19
|
+
query: (query: string, options: {
|
|
20
|
+
limit?: number;
|
|
21
|
+
cursor?: string;
|
|
22
|
+
fuzzyOptions?: Record<string, unknown>;
|
|
23
|
+
}) => Promise<SearchQueryResponse>;
|
|
24
|
+
}
|
|
25
|
+
interface SearchIndex {
|
|
26
|
+
PUT: (docs: Record<string, unknown>[]) => Promise<unknown>;
|
|
27
|
+
DELETE: (id: string) => Promise<unknown>;
|
|
28
|
+
QUERY: (query: {
|
|
29
|
+
AND?: string[];
|
|
30
|
+
OR?: string[];
|
|
31
|
+
}, options: SearchIndexOptions) => Promise<SearchIndexResult>;
|
|
32
|
+
fuzzySearchWrapper?: FuzzySearchWrapper;
|
|
33
|
+
}
|
|
34
|
+
interface RequestWithBody extends IncomingMessage {
|
|
35
|
+
body?: {
|
|
36
|
+
docs?: Record<string, unknown>[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
5
39
|
export declare const createSearchIndexRouter: ({ config, searchIndex, }: {
|
|
6
40
|
config: PathConfig;
|
|
7
|
-
searchIndex:
|
|
41
|
+
searchIndex: SearchIndex;
|
|
8
42
|
}) => {
|
|
9
|
-
del: (req:
|
|
10
|
-
get: (req:
|
|
11
|
-
put: (req:
|
|
43
|
+
del: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
44
|
+
get: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
45
|
+
put: (req: RequestWithBody, res: ServerResponse) => Promise<void>;
|
|
12
46
|
};
|
|
47
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -88,12 +88,12 @@
|
|
|
88
88
|
"vite": "^4.5.9",
|
|
89
89
|
"yup": "^1.6.1",
|
|
90
90
|
"zod": "^3.24.2",
|
|
91
|
-
"@tinacms/app": "2.3.
|
|
92
|
-
"@tinacms/graphql": "2.0.
|
|
93
|
-
"@tinacms/
|
|
94
|
-
"@tinacms/
|
|
95
|
-
"tinacms": "3.
|
|
96
|
-
"
|
|
91
|
+
"@tinacms/app": "2.3.20",
|
|
92
|
+
"@tinacms/graphql": "2.0.6",
|
|
93
|
+
"@tinacms/search": "1.2.0",
|
|
94
|
+
"@tinacms/metrics": "2.0.1",
|
|
95
|
+
"@tinacms/schema-tools": "2.3.0",
|
|
96
|
+
"tinacms": "3.3.0"
|
|
97
97
|
},
|
|
98
98
|
"publishConfig": {
|
|
99
99
|
"registry": "https://registry.npmjs.org"
|