@tinacms/schema-tools 1.4.4 → 1.4.6

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 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,21 @@ 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
+ stopwordLanguages: z$1.array(z$1.string()).nonempty().optional()
894
+ }).strict().optional();
884
895
  const tinaConfigZod = z$1.object({
885
896
  client: z$1.object({ referenceDepth: z$1.number().optional() }).optional(),
886
897
  media: z$1.object({
887
898
  tina: tinaConfigKey,
888
899
  loadCustomStore: z$1.function().optional()
900
+ }).optional(),
901
+ search: z$1.object({
902
+ tina: tinaSearchKey,
903
+ searchClient: z$1.any().optional(),
904
+ indexBatchSize: z$1.number().gte(1).optional(),
905
+ maxSearchIndexFieldLength: z$1.number().gte(1).optional()
889
906
  }).optional()
890
907
  });
891
908
  const validateTinaCloudSchemaConfig = (config) => {
@@ -975,7 +992,7 @@ const TinaCloudSchemaZod = z.object({
975
992
  collections: z.array(TinaCloudCollection),
976
993
  config: tinaConfigZod.optional()
977
994
  }).superRefine((val, ctx) => {
978
- var _a, _b;
995
+ var _a, _b, _c;
979
996
  const dups = findDuplicates((_a = val.collections) == null ? void 0 : _a.map((x) => x.name));
980
997
  if (dups) {
981
998
  ctx.addIssue({
@@ -993,6 +1010,15 @@ const TinaCloudSchemaZod = z.object({
993
1010
  path: ["config", "media"]
994
1011
  });
995
1012
  }
1013
+ const search = (_c = val == null ? void 0 : val.config) == null ? void 0 : _c.search;
1014
+ if (search && search.tina && search.searchClient) {
1015
+ ctx.addIssue({
1016
+ code: z.ZodIssueCode.custom,
1017
+ message: "can not have both searchClient and tina. Must use one or the other",
1018
+ fatal: true,
1019
+ path: ["config", "search"]
1020
+ });
1021
+ }
996
1022
  });
997
1023
  class TinaSchemaValidationError extends Error {
998
1024
  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,21 @@ ${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
+ stopwordLanguages: z__default["default"].array(z__default["default"].string()).nonempty().optional()
921
+ }).strict().optional();
911
922
  const tinaConfigZod = z__default["default"].object({
912
923
  client: z__default["default"].object({ referenceDepth: z__default["default"].number().optional() }).optional(),
913
924
  media: z__default["default"].object({
914
925
  tina: tinaConfigKey,
915
926
  loadCustomStore: z__default["default"].function().optional()
927
+ }).optional(),
928
+ search: z__default["default"].object({
929
+ tina: tinaSearchKey,
930
+ searchClient: z__default["default"].any().optional(),
931
+ indexBatchSize: z__default["default"].number().gte(1).optional(),
932
+ maxSearchIndexFieldLength: z__default["default"].number().gte(1).optional()
916
933
  }).optional()
917
934
  });
918
935
  const validateTinaCloudSchemaConfig = (config) => {
@@ -1002,7 +1019,7 @@ ${JSON.stringify(val, null, 2)}
1002
1019
  collections: z.z.array(TinaCloudCollection),
1003
1020
  config: tinaConfigZod.optional()
1004
1021
  }).superRefine((val, ctx) => {
1005
- var _a, _b;
1022
+ var _a, _b, _c;
1006
1023
  const dups = findDuplicates((_a = val.collections) == null ? void 0 : _a.map((x) => x.name));
1007
1024
  if (dups) {
1008
1025
  ctx.addIssue({
@@ -1020,6 +1037,15 @@ ${JSON.stringify(val, null, 2)}
1020
1037
  path: ["config", "media"]
1021
1038
  });
1022
1039
  }
1040
+ const search = (_c = val == null ? void 0 : val.config) == null ? void 0 : _c.search;
1041
+ if (search && search.tina && search.searchClient) {
1042
+ ctx.addIssue({
1043
+ code: z.z.ZodIssueCode.custom,
1044
+ message: "can not have both searchClient and tina. Must use one or the other",
1045
+ fatal: true,
1046
+ path: ["config", "search"]
1047
+ });
1048
+ }
1023
1049
  });
1024
1050
  class TinaSchemaValidationError extends Error {
1025
1051
  constructor(message) {
@@ -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,47 @@ 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
+ stopwordLanguages: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
140
+ }, "strict", z.ZodTypeAny, {
141
+ indexerToken?: string;
142
+ stopwordLanguages?: [string, ...string[]];
143
+ }, {
144
+ indexerToken?: string;
145
+ stopwordLanguages?: [string, ...string[]];
146
+ }>>;
147
+ searchClient: z.ZodOptional<z.ZodAny>;
148
+ indexBatchSize: z.ZodOptional<z.ZodNumber>;
149
+ maxSearchIndexFieldLength: z.ZodOptional<z.ZodNumber>;
150
+ }, "strip", z.ZodTypeAny, {
151
+ maxSearchIndexFieldLength?: number;
152
+ tina?: {
153
+ indexerToken?: string;
154
+ stopwordLanguages?: [string, ...string[]];
155
+ };
156
+ searchClient?: any;
157
+ indexBatchSize?: number;
158
+ }, {
159
+ maxSearchIndexFieldLength?: number;
160
+ tina?: {
161
+ indexerToken?: string;
162
+ stopwordLanguages?: [string, ...string[]];
163
+ };
164
+ searchClient?: any;
165
+ indexBatchSize?: number;
166
+ }>>;
136
167
  }, "strip", z.ZodTypeAny, {
168
+ search?: {
169
+ maxSearchIndexFieldLength?: number;
170
+ tina?: {
171
+ indexerToken?: string;
172
+ stopwordLanguages?: [string, ...string[]];
173
+ };
174
+ searchClient?: any;
175
+ indexBatchSize?: number;
176
+ };
137
177
  client?: {
138
178
  referenceDepth?: number;
139
179
  };
@@ -145,6 +185,15 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
145
185
  loadCustomStore?: (...args: unknown[]) => unknown;
146
186
  };
147
187
  }, {
188
+ search?: {
189
+ maxSearchIndexFieldLength?: number;
190
+ tina?: {
191
+ indexerToken?: string;
192
+ stopwordLanguages?: [string, ...string[]];
193
+ };
194
+ searchClient?: any;
195
+ indexBatchSize?: number;
196
+ };
148
197
  client?: {
149
198
  referenceDepth?: number;
150
199
  };
@@ -170,6 +219,15 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
170
219
  format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
171
220
  }[];
172
221
  config?: {
222
+ search?: {
223
+ maxSearchIndexFieldLength?: number;
224
+ tina?: {
225
+ indexerToken?: string;
226
+ stopwordLanguages?: [string, ...string[]];
227
+ };
228
+ searchClient?: any;
229
+ indexBatchSize?: number;
230
+ };
173
231
  client?: {
174
232
  referenceDepth?: number;
175
233
  };
@@ -195,6 +253,15 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
195
253
  format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
196
254
  }[];
197
255
  config?: {
256
+ search?: {
257
+ maxSearchIndexFieldLength?: number;
258
+ tina?: {
259
+ indexerToken?: string;
260
+ stopwordLanguages?: [string, ...string[]];
261
+ };
262
+ searchClient?: any;
263
+ indexBatchSize?: number;
264
+ };
198
265
  client?: {
199
266
  referenceDepth?: number;
200
267
  };
@@ -220,6 +287,15 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
220
287
  format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
221
288
  }[];
222
289
  config?: {
290
+ search?: {
291
+ maxSearchIndexFieldLength?: number;
292
+ tina?: {
293
+ indexerToken?: string;
294
+ stopwordLanguages?: [string, ...string[]];
295
+ };
296
+ searchClient?: any;
297
+ indexBatchSize?: number;
298
+ };
223
299
  client?: {
224
300
  referenceDepth?: number;
225
301
  };
@@ -245,6 +321,15 @@ export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
245
321
  format?: "markdown" | "mdx" | "json" | "md" | "yaml" | "yml" | "toml";
246
322
  }[];
247
323
  config?: {
324
+ search?: {
325
+ maxSearchIndexFieldLength?: number;
326
+ tina?: {
327
+ indexerToken?: string;
328
+ stopwordLanguages?: [string, ...string[]];
329
+ };
330
+ searchClient?: any;
331
+ indexBatchSize?: number;
332
+ };
248
333
  client?: {
249
334
  referenceDepth?: number;
250
335
  };
@@ -36,7 +36,47 @@ 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
+ stopwordLanguages: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
43
+ }, "strict", z.ZodTypeAny, {
44
+ indexerToken?: string;
45
+ stopwordLanguages?: [string, ...string[]];
46
+ }, {
47
+ indexerToken?: string;
48
+ stopwordLanguages?: [string, ...string[]];
49
+ }>>;
50
+ searchClient: z.ZodOptional<z.ZodAny>;
51
+ indexBatchSize: z.ZodOptional<z.ZodNumber>;
52
+ maxSearchIndexFieldLength: z.ZodOptional<z.ZodNumber>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ maxSearchIndexFieldLength?: number;
55
+ tina?: {
56
+ indexerToken?: string;
57
+ stopwordLanguages?: [string, ...string[]];
58
+ };
59
+ searchClient?: any;
60
+ indexBatchSize?: number;
61
+ }, {
62
+ maxSearchIndexFieldLength?: number;
63
+ tina?: {
64
+ indexerToken?: string;
65
+ stopwordLanguages?: [string, ...string[]];
66
+ };
67
+ searchClient?: any;
68
+ indexBatchSize?: number;
69
+ }>>;
39
70
  }, "strip", z.ZodTypeAny, {
71
+ search?: {
72
+ maxSearchIndexFieldLength?: number;
73
+ tina?: {
74
+ indexerToken?: string;
75
+ stopwordLanguages?: [string, ...string[]];
76
+ };
77
+ searchClient?: any;
78
+ indexBatchSize?: number;
79
+ };
40
80
  client?: {
41
81
  referenceDepth?: number;
42
82
  };
@@ -48,6 +88,15 @@ export declare const tinaConfigZod: z.ZodObject<{
48
88
  loadCustomStore?: (...args: unknown[]) => unknown;
49
89
  };
50
90
  }, {
91
+ search?: {
92
+ maxSearchIndexFieldLength?: number;
93
+ tina?: {
94
+ indexerToken?: string;
95
+ stopwordLanguages?: [string, ...string[]];
96
+ };
97
+ searchClient?: any;
98
+ indexBatchSize?: number;
99
+ };
51
100
  client?: {
52
101
  referenceDepth?: number;
53
102
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {