@tinacms/schema-tools 1.4.4 → 1.4.5
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.es.js +24 -1
- package/dist/index.js +24 -1
- package/dist/types/index.d.ts +38 -3
- package/dist/validate/schema.d.ts +56 -0
- package/dist/validate/tinaCloudSchemaConfig.d.ts +32 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -424,6 +424,13 @@ class TinaSchema {
|
|
|
424
424
|
this.schema = config;
|
|
425
425
|
this.walkFields(({ field, collection, path }) => {
|
|
426
426
|
var _a;
|
|
427
|
+
if (!("searchable" in field)) {
|
|
428
|
+
if (field.type === "image") {
|
|
429
|
+
field.searchable = false;
|
|
430
|
+
} else {
|
|
431
|
+
field.searchable = true;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
427
434
|
if (field.type === "rich-text") {
|
|
428
435
|
if (field.parser) {
|
|
429
436
|
return;
|
|
@@ -881,11 +888,18 @@ const tinaConfigKey = z$1.object({
|
|
|
881
888
|
publicFolder: z$1.string(),
|
|
882
889
|
mediaRoot: z$1.string()
|
|
883
890
|
}).strict().optional();
|
|
891
|
+
const tinaSearchKey = z$1.object({
|
|
892
|
+
indexerToken: z$1.string().optional()
|
|
893
|
+
}).strict().optional();
|
|
884
894
|
const tinaConfigZod = z$1.object({
|
|
885
895
|
client: z$1.object({ referenceDepth: z$1.number().optional() }).optional(),
|
|
886
896
|
media: z$1.object({
|
|
887
897
|
tina: tinaConfigKey,
|
|
888
898
|
loadCustomStore: z$1.function().optional()
|
|
899
|
+
}).optional(),
|
|
900
|
+
search: z$1.object({
|
|
901
|
+
tina: tinaSearchKey,
|
|
902
|
+
searchClient: z$1.any().optional()
|
|
889
903
|
}).optional()
|
|
890
904
|
});
|
|
891
905
|
const validateTinaCloudSchemaConfig = (config) => {
|
|
@@ -975,7 +989,7 @@ const TinaCloudSchemaZod = z.object({
|
|
|
975
989
|
collections: z.array(TinaCloudCollection),
|
|
976
990
|
config: tinaConfigZod.optional()
|
|
977
991
|
}).superRefine((val, ctx) => {
|
|
978
|
-
var _a, _b;
|
|
992
|
+
var _a, _b, _c;
|
|
979
993
|
const dups = findDuplicates((_a = val.collections) == null ? void 0 : _a.map((x) => x.name));
|
|
980
994
|
if (dups) {
|
|
981
995
|
ctx.addIssue({
|
|
@@ -993,6 +1007,15 @@ const TinaCloudSchemaZod = z.object({
|
|
|
993
1007
|
path: ["config", "media"]
|
|
994
1008
|
});
|
|
995
1009
|
}
|
|
1010
|
+
const search = (_c = val == null ? void 0 : val.config) == null ? void 0 : _c.search;
|
|
1011
|
+
if (search && search.tina && search.searchClient) {
|
|
1012
|
+
ctx.addIssue({
|
|
1013
|
+
code: z.ZodIssueCode.custom,
|
|
1014
|
+
message: "can not have both searchClient and tina. Must use one or the other",
|
|
1015
|
+
fatal: true,
|
|
1016
|
+
path: ["config", "search"]
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
996
1019
|
});
|
|
997
1020
|
class TinaSchemaValidationError extends Error {
|
|
998
1021
|
constructor(message) {
|
package/dist/index.js
CHANGED
|
@@ -451,6 +451,13 @@
|
|
|
451
451
|
this.schema = config;
|
|
452
452
|
this.walkFields(({ field, collection, path }) => {
|
|
453
453
|
var _a;
|
|
454
|
+
if (!("searchable" in field)) {
|
|
455
|
+
if (field.type === "image") {
|
|
456
|
+
field.searchable = false;
|
|
457
|
+
} else {
|
|
458
|
+
field.searchable = true;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
454
461
|
if (field.type === "rich-text") {
|
|
455
462
|
if (field.parser) {
|
|
456
463
|
return;
|
|
@@ -908,11 +915,18 @@ ${JSON.stringify(val, null, 2)}
|
|
|
908
915
|
publicFolder: z__default["default"].string(),
|
|
909
916
|
mediaRoot: z__default["default"].string()
|
|
910
917
|
}).strict().optional();
|
|
918
|
+
const tinaSearchKey = z__default["default"].object({
|
|
919
|
+
indexerToken: z__default["default"].string().optional()
|
|
920
|
+
}).strict().optional();
|
|
911
921
|
const tinaConfigZod = z__default["default"].object({
|
|
912
922
|
client: z__default["default"].object({ referenceDepth: z__default["default"].number().optional() }).optional(),
|
|
913
923
|
media: z__default["default"].object({
|
|
914
924
|
tina: tinaConfigKey,
|
|
915
925
|
loadCustomStore: z__default["default"].function().optional()
|
|
926
|
+
}).optional(),
|
|
927
|
+
search: z__default["default"].object({
|
|
928
|
+
tina: tinaSearchKey,
|
|
929
|
+
searchClient: z__default["default"].any().optional()
|
|
916
930
|
}).optional()
|
|
917
931
|
});
|
|
918
932
|
const validateTinaCloudSchemaConfig = (config) => {
|
|
@@ -1002,7 +1016,7 @@ ${JSON.stringify(val, null, 2)}
|
|
|
1002
1016
|
collections: z.z.array(TinaCloudCollection),
|
|
1003
1017
|
config: tinaConfigZod.optional()
|
|
1004
1018
|
}).superRefine((val, ctx) => {
|
|
1005
|
-
var _a, _b;
|
|
1019
|
+
var _a, _b, _c;
|
|
1006
1020
|
const dups = findDuplicates((_a = val.collections) == null ? void 0 : _a.map((x) => x.name));
|
|
1007
1021
|
if (dups) {
|
|
1008
1022
|
ctx.addIssue({
|
|
@@ -1020,6 +1034,15 @@ ${JSON.stringify(val, null, 2)}
|
|
|
1020
1034
|
path: ["config", "media"]
|
|
1021
1035
|
});
|
|
1022
1036
|
}
|
|
1037
|
+
const search = (_c = val == null ? void 0 : val.config) == null ? void 0 : _c.search;
|
|
1038
|
+
if (search && search.tina && search.searchClient) {
|
|
1039
|
+
ctx.addIssue({
|
|
1040
|
+
code: z.z.ZodIssueCode.custom,
|
|
1041
|
+
message: "can not have both searchClient and tina. Must use one or the other",
|
|
1042
|
+
fatal: true,
|
|
1043
|
+
path: ["config", "search"]
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1023
1046
|
});
|
|
1024
1047
|
class TinaSchemaValidationError extends Error {
|
|
1025
1048
|
constructor(message) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -117,6 +117,9 @@ declare type FieldGeneric<Type, List extends boolean | undefined, ExtraFieldUIPr
|
|
|
117
117
|
list?: undefined;
|
|
118
118
|
ui?: UIField<Type, false> & ExtraFieldUIProps;
|
|
119
119
|
};
|
|
120
|
+
declare type SearchableTextField = {
|
|
121
|
+
maxSearchIndexFieldLength?: number;
|
|
122
|
+
};
|
|
120
123
|
export interface BaseField {
|
|
121
124
|
label?: string | boolean;
|
|
122
125
|
required?: boolean;
|
|
@@ -124,8 +127,9 @@ export interface BaseField {
|
|
|
124
127
|
name: string;
|
|
125
128
|
nameOverride?: string;
|
|
126
129
|
description?: string;
|
|
130
|
+
searchable?: boolean;
|
|
127
131
|
}
|
|
128
|
-
export declare type StringField = (FieldGeneric<string, undefined> | FieldGeneric<string, true> | FieldGeneric<string, false>) & BaseField & {
|
|
132
|
+
export declare type StringField = (FieldGeneric<string, undefined> | FieldGeneric<string, true> | FieldGeneric<string, false>) & BaseField & SearchableTextField & {
|
|
129
133
|
type: 'string';
|
|
130
134
|
isTitle?: boolean;
|
|
131
135
|
isBody?: boolean;
|
|
@@ -171,7 +175,7 @@ declare type RichTextAst = {
|
|
|
171
175
|
type: 'root';
|
|
172
176
|
children: Record<string, unknown>[];
|
|
173
177
|
};
|
|
174
|
-
export declare type RichTextField<WithNamespace extends boolean = false> = (FieldGeneric<RichTextAst, undefined> | FieldGeneric<RichTextAst, false>) & BaseField & {
|
|
178
|
+
export declare type RichTextField<WithNamespace extends boolean = false> = (FieldGeneric<RichTextAst, undefined> | FieldGeneric<RichTextAst, false>) & BaseField & SearchableTextField & {
|
|
175
179
|
type: 'rich-text';
|
|
176
180
|
/**
|
|
177
181
|
* When using Markdown or MDX formats, this field's value
|
|
@@ -280,7 +284,7 @@ declare type TokenObject = {
|
|
|
280
284
|
access_token?: string;
|
|
281
285
|
refresh_token?: string;
|
|
282
286
|
};
|
|
283
|
-
export interface Config<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined> {
|
|
287
|
+
export interface Config<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined, SearchClient = undefined> {
|
|
284
288
|
contentApiUrlOverride?: string;
|
|
285
289
|
admin?: {
|
|
286
290
|
auth?: {
|
|
@@ -428,6 +432,37 @@ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, Do
|
|
|
428
432
|
};
|
|
429
433
|
loadCustomStore?: never;
|
|
430
434
|
};
|
|
435
|
+
search?: ({
|
|
436
|
+
/**
|
|
437
|
+
* An instance of a search client like Algolia
|
|
438
|
+
*/
|
|
439
|
+
searchClient: SearchClient;
|
|
440
|
+
tina?: never;
|
|
441
|
+
} | {
|
|
442
|
+
searchClient?: never;
|
|
443
|
+
/**
|
|
444
|
+
* Use the Tina Cloud search index
|
|
445
|
+
*/
|
|
446
|
+
tina: {
|
|
447
|
+
/**
|
|
448
|
+
* Search index token with permissions to write to search index. Only used by CLI.
|
|
449
|
+
*/
|
|
450
|
+
indexerToken?: string;
|
|
451
|
+
/**
|
|
452
|
+
* stopword languages to use (default: eng)
|
|
453
|
+
*/
|
|
454
|
+
stopwordLanguages?: string[];
|
|
455
|
+
};
|
|
456
|
+
}) & {
|
|
457
|
+
/**
|
|
458
|
+
* The number of documents to index per PUT request
|
|
459
|
+
*/
|
|
460
|
+
indexBatchSize?: number;
|
|
461
|
+
/**
|
|
462
|
+
* The maximum length of a string field that will be indexed for search
|
|
463
|
+
*/
|
|
464
|
+
maxSearchIndexFieldLength?: number;
|
|
465
|
+
};
|
|
431
466
|
/**
|
|
432
467
|
* Used to override the default Tina Cloud API URL
|
|
433
468
|
*
|
|
@@ -133,7 +133,33 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
|
133
133
|
};
|
|
134
134
|
loadCustomStore?: (...args: unknown[]) => unknown;
|
|
135
135
|
}>>;
|
|
136
|
+
search: z.ZodOptional<z.ZodObject<{
|
|
137
|
+
tina: z.ZodOptional<z.ZodObject<{
|
|
138
|
+
indexerToken: z.ZodOptional<z.ZodString>;
|
|
139
|
+
}, "strict", z.ZodTypeAny, {
|
|
140
|
+
indexerToken?: string;
|
|
141
|
+
}, {
|
|
142
|
+
indexerToken?: string;
|
|
143
|
+
}>>;
|
|
144
|
+
searchClient: z.ZodOptional<z.ZodAny>;
|
|
145
|
+
}, "strip", z.ZodTypeAny, {
|
|
146
|
+
tina?: {
|
|
147
|
+
indexerToken?: string;
|
|
148
|
+
};
|
|
149
|
+
searchClient?: any;
|
|
150
|
+
}, {
|
|
151
|
+
tina?: {
|
|
152
|
+
indexerToken?: string;
|
|
153
|
+
};
|
|
154
|
+
searchClient?: any;
|
|
155
|
+
}>>;
|
|
136
156
|
}, "strip", z.ZodTypeAny, {
|
|
157
|
+
search?: {
|
|
158
|
+
tina?: {
|
|
159
|
+
indexerToken?: string;
|
|
160
|
+
};
|
|
161
|
+
searchClient?: any;
|
|
162
|
+
};
|
|
137
163
|
client?: {
|
|
138
164
|
referenceDepth?: number;
|
|
139
165
|
};
|
|
@@ -145,6 +171,12 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
|
145
171
|
loadCustomStore?: (...args: unknown[]) => unknown;
|
|
146
172
|
};
|
|
147
173
|
}, {
|
|
174
|
+
search?: {
|
|
175
|
+
tina?: {
|
|
176
|
+
indexerToken?: string;
|
|
177
|
+
};
|
|
178
|
+
searchClient?: any;
|
|
179
|
+
};
|
|
148
180
|
client?: {
|
|
149
181
|
referenceDepth?: number;
|
|
150
182
|
};
|
|
@@ -170,6 +202,12 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
|
170
202
|
format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
|
|
171
203
|
}[];
|
|
172
204
|
config?: {
|
|
205
|
+
search?: {
|
|
206
|
+
tina?: {
|
|
207
|
+
indexerToken?: string;
|
|
208
|
+
};
|
|
209
|
+
searchClient?: any;
|
|
210
|
+
};
|
|
173
211
|
client?: {
|
|
174
212
|
referenceDepth?: number;
|
|
175
213
|
};
|
|
@@ -195,6 +233,12 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
|
195
233
|
format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
|
|
196
234
|
}[];
|
|
197
235
|
config?: {
|
|
236
|
+
search?: {
|
|
237
|
+
tina?: {
|
|
238
|
+
indexerToken?: string;
|
|
239
|
+
};
|
|
240
|
+
searchClient?: any;
|
|
241
|
+
};
|
|
198
242
|
client?: {
|
|
199
243
|
referenceDepth?: number;
|
|
200
244
|
};
|
|
@@ -220,6 +264,12 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
|
220
264
|
format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
|
|
221
265
|
}[];
|
|
222
266
|
config?: {
|
|
267
|
+
search?: {
|
|
268
|
+
tina?: {
|
|
269
|
+
indexerToken?: string;
|
|
270
|
+
};
|
|
271
|
+
searchClient?: any;
|
|
272
|
+
};
|
|
223
273
|
client?: {
|
|
224
274
|
referenceDepth?: number;
|
|
225
275
|
};
|
|
@@ -245,6 +295,12 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
|
|
|
245
295
|
format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
|
|
246
296
|
}[];
|
|
247
297
|
config?: {
|
|
298
|
+
search?: {
|
|
299
|
+
tina?: {
|
|
300
|
+
indexerToken?: string;
|
|
301
|
+
};
|
|
302
|
+
searchClient?: any;
|
|
303
|
+
};
|
|
248
304
|
client?: {
|
|
249
305
|
referenceDepth?: number;
|
|
250
306
|
};
|
|
@@ -36,7 +36,33 @@ export declare const tinaConfigZod: z.ZodObject<{
|
|
|
36
36
|
};
|
|
37
37
|
loadCustomStore?: (...args: unknown[]) => unknown;
|
|
38
38
|
}>>;
|
|
39
|
+
search: z.ZodOptional<z.ZodObject<{
|
|
40
|
+
tina: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
indexerToken: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, "strict", z.ZodTypeAny, {
|
|
43
|
+
indexerToken?: string;
|
|
44
|
+
}, {
|
|
45
|
+
indexerToken?: string;
|
|
46
|
+
}>>;
|
|
47
|
+
searchClient: z.ZodOptional<z.ZodAny>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
tina?: {
|
|
50
|
+
indexerToken?: string;
|
|
51
|
+
};
|
|
52
|
+
searchClient?: any;
|
|
53
|
+
}, {
|
|
54
|
+
tina?: {
|
|
55
|
+
indexerToken?: string;
|
|
56
|
+
};
|
|
57
|
+
searchClient?: any;
|
|
58
|
+
}>>;
|
|
39
59
|
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
search?: {
|
|
61
|
+
tina?: {
|
|
62
|
+
indexerToken?: string;
|
|
63
|
+
};
|
|
64
|
+
searchClient?: any;
|
|
65
|
+
};
|
|
40
66
|
client?: {
|
|
41
67
|
referenceDepth?: number;
|
|
42
68
|
};
|
|
@@ -48,6 +74,12 @@ export declare const tinaConfigZod: z.ZodObject<{
|
|
|
48
74
|
loadCustomStore?: (...args: unknown[]) => unknown;
|
|
49
75
|
};
|
|
50
76
|
}, {
|
|
77
|
+
search?: {
|
|
78
|
+
tina?: {
|
|
79
|
+
indexerToken?: string;
|
|
80
|
+
};
|
|
81
|
+
searchClient?: any;
|
|
82
|
+
};
|
|
51
83
|
client?: {
|
|
52
84
|
referenceDepth?: number;
|
|
53
85
|
};
|