@magicpages/ghost-typesense-config 1.3.1 → 1.4.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.d.mts CHANGED
@@ -155,12 +155,16 @@ declare const REQUIRED_FIELDS: {
155
155
  readonly description: "Post last update timestamp";
156
156
  };
157
157
  };
158
+ /**
159
+ * Default collection fields that should be included
160
+ */
161
+ declare const DEFAULT_COLLECTION_FIELDS: CollectionField[];
158
162
  /**
159
163
  * Collection configuration schema with strict validation
160
164
  */
161
165
  declare const CollectionConfigSchema: z.ZodObject<{
162
166
  name: z.ZodString;
163
- fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
167
+ fields: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
164
168
  name: z.ZodString;
165
169
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
166
170
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -195,7 +199,21 @@ declare const CollectionConfigSchema: z.ZodObject<{
195
199
  facet?: boolean | undefined;
196
200
  index?: boolean | undefined;
197
201
  optional?: boolean | undefined;
198
- }>, "many">, {
202
+ }>, "many">>, {
203
+ optional: boolean;
204
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
205
+ name: string;
206
+ sort?: boolean | undefined;
207
+ facet?: boolean | undefined;
208
+ index?: boolean | undefined;
209
+ }[], {
210
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
211
+ name: string;
212
+ sort?: boolean | undefined;
213
+ facet?: boolean | undefined;
214
+ index?: boolean | undefined;
215
+ optional?: boolean | undefined;
216
+ }[] | undefined>, {
199
217
  optional: boolean;
200
218
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
201
219
  name: string;
@@ -209,7 +227,7 @@ declare const CollectionConfigSchema: z.ZodObject<{
209
227
  facet?: boolean | undefined;
210
228
  index?: boolean | undefined;
211
229
  optional?: boolean | undefined;
212
- }[]>;
230
+ }[] | undefined>;
213
231
  default_sorting_field: z.ZodOptional<z.ZodString>;
214
232
  }, "strip", z.ZodTypeAny, {
215
233
  name: string;
@@ -224,14 +242,14 @@ declare const CollectionConfigSchema: z.ZodObject<{
224
242
  default_sorting_field?: string | undefined;
225
243
  }, {
226
244
  name: string;
227
- fields: {
245
+ fields?: {
228
246
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
229
247
  name: string;
230
248
  sort?: boolean | undefined;
231
249
  facet?: boolean | undefined;
232
250
  index?: boolean | undefined;
233
251
  optional?: boolean | undefined;
234
- }[];
252
+ }[] | undefined;
235
253
  default_sorting_field?: string | undefined;
236
254
  }>;
237
255
  /**
@@ -294,7 +312,7 @@ declare const ConfigSchema: z.ZodObject<{
294
312
  }>;
295
313
  collection: z.ZodObject<{
296
314
  name: z.ZodString;
297
- fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
315
+ fields: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
298
316
  name: z.ZodString;
299
317
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
300
318
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -329,7 +347,21 @@ declare const ConfigSchema: z.ZodObject<{
329
347
  facet?: boolean | undefined;
330
348
  index?: boolean | undefined;
331
349
  optional?: boolean | undefined;
332
- }>, "many">, {
350
+ }>, "many">>, {
351
+ optional: boolean;
352
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
353
+ name: string;
354
+ sort?: boolean | undefined;
355
+ facet?: boolean | undefined;
356
+ index?: boolean | undefined;
357
+ }[], {
358
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
359
+ name: string;
360
+ sort?: boolean | undefined;
361
+ facet?: boolean | undefined;
362
+ index?: boolean | undefined;
363
+ optional?: boolean | undefined;
364
+ }[] | undefined>, {
333
365
  optional: boolean;
334
366
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
335
367
  name: string;
@@ -343,7 +375,7 @@ declare const ConfigSchema: z.ZodObject<{
343
375
  facet?: boolean | undefined;
344
376
  index?: boolean | undefined;
345
377
  optional?: boolean | undefined;
346
- }[]>;
378
+ }[] | undefined>;
347
379
  default_sorting_field: z.ZodOptional<z.ZodString>;
348
380
  }, "strip", z.ZodTypeAny, {
349
381
  name: string;
@@ -358,14 +390,14 @@ declare const ConfigSchema: z.ZodObject<{
358
390
  default_sorting_field?: string | undefined;
359
391
  }, {
360
392
  name: string;
361
- fields: {
393
+ fields?: {
362
394
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
363
395
  name: string;
364
396
  sort?: boolean | undefined;
365
397
  facet?: boolean | undefined;
366
398
  index?: boolean | undefined;
367
399
  optional?: boolean | undefined;
368
- }[];
400
+ }[] | undefined;
369
401
  default_sorting_field?: string | undefined;
370
402
  }>;
371
403
  }, "strip", z.ZodTypeAny, {
@@ -416,14 +448,14 @@ declare const ConfigSchema: z.ZodObject<{
416
448
  };
417
449
  collection: {
418
450
  name: string;
419
- fields: {
451
+ fields?: {
420
452
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
421
453
  name: string;
422
454
  sort?: boolean | undefined;
423
455
  facet?: boolean | undefined;
424
456
  index?: boolean | undefined;
425
457
  optional?: boolean | undefined;
426
- }[];
458
+ }[] | undefined;
427
459
  default_sorting_field?: string | undefined;
428
460
  };
429
461
  }>;
@@ -443,10 +475,6 @@ type Config = z.infer<typeof ConfigSchema>;
443
475
  * @throws {ZodError} If validation fails
444
476
  */
445
477
  declare function validateConfig(config: unknown): Config;
446
- /**
447
- * Default collection fields that should be included
448
- */
449
- declare const DEFAULT_COLLECTION_FIELDS: CollectionField[];
450
478
  /**
451
479
  * Creates a default configuration object
452
480
  * @param ghostUrl The URL of the Ghost instance
package/dist/index.d.ts CHANGED
@@ -155,12 +155,16 @@ declare const REQUIRED_FIELDS: {
155
155
  readonly description: "Post last update timestamp";
156
156
  };
157
157
  };
158
+ /**
159
+ * Default collection fields that should be included
160
+ */
161
+ declare const DEFAULT_COLLECTION_FIELDS: CollectionField[];
158
162
  /**
159
163
  * Collection configuration schema with strict validation
160
164
  */
161
165
  declare const CollectionConfigSchema: z.ZodObject<{
162
166
  name: z.ZodString;
163
- fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
167
+ fields: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
164
168
  name: z.ZodString;
165
169
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
166
170
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -195,7 +199,21 @@ declare const CollectionConfigSchema: z.ZodObject<{
195
199
  facet?: boolean | undefined;
196
200
  index?: boolean | undefined;
197
201
  optional?: boolean | undefined;
198
- }>, "many">, {
202
+ }>, "many">>, {
203
+ optional: boolean;
204
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
205
+ name: string;
206
+ sort?: boolean | undefined;
207
+ facet?: boolean | undefined;
208
+ index?: boolean | undefined;
209
+ }[], {
210
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
211
+ name: string;
212
+ sort?: boolean | undefined;
213
+ facet?: boolean | undefined;
214
+ index?: boolean | undefined;
215
+ optional?: boolean | undefined;
216
+ }[] | undefined>, {
199
217
  optional: boolean;
200
218
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
201
219
  name: string;
@@ -209,7 +227,7 @@ declare const CollectionConfigSchema: z.ZodObject<{
209
227
  facet?: boolean | undefined;
210
228
  index?: boolean | undefined;
211
229
  optional?: boolean | undefined;
212
- }[]>;
230
+ }[] | undefined>;
213
231
  default_sorting_field: z.ZodOptional<z.ZodString>;
214
232
  }, "strip", z.ZodTypeAny, {
215
233
  name: string;
@@ -224,14 +242,14 @@ declare const CollectionConfigSchema: z.ZodObject<{
224
242
  default_sorting_field?: string | undefined;
225
243
  }, {
226
244
  name: string;
227
- fields: {
245
+ fields?: {
228
246
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
229
247
  name: string;
230
248
  sort?: boolean | undefined;
231
249
  facet?: boolean | undefined;
232
250
  index?: boolean | undefined;
233
251
  optional?: boolean | undefined;
234
- }[];
252
+ }[] | undefined;
235
253
  default_sorting_field?: string | undefined;
236
254
  }>;
237
255
  /**
@@ -294,7 +312,7 @@ declare const ConfigSchema: z.ZodObject<{
294
312
  }>;
295
313
  collection: z.ZodObject<{
296
314
  name: z.ZodString;
297
- fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
315
+ fields: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
298
316
  name: z.ZodString;
299
317
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
300
318
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -329,7 +347,21 @@ declare const ConfigSchema: z.ZodObject<{
329
347
  facet?: boolean | undefined;
330
348
  index?: boolean | undefined;
331
349
  optional?: boolean | undefined;
332
- }>, "many">, {
350
+ }>, "many">>, {
351
+ optional: boolean;
352
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
353
+ name: string;
354
+ sort?: boolean | undefined;
355
+ facet?: boolean | undefined;
356
+ index?: boolean | undefined;
357
+ }[], {
358
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
359
+ name: string;
360
+ sort?: boolean | undefined;
361
+ facet?: boolean | undefined;
362
+ index?: boolean | undefined;
363
+ optional?: boolean | undefined;
364
+ }[] | undefined>, {
333
365
  optional: boolean;
334
366
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
335
367
  name: string;
@@ -343,7 +375,7 @@ declare const ConfigSchema: z.ZodObject<{
343
375
  facet?: boolean | undefined;
344
376
  index?: boolean | undefined;
345
377
  optional?: boolean | undefined;
346
- }[]>;
378
+ }[] | undefined>;
347
379
  default_sorting_field: z.ZodOptional<z.ZodString>;
348
380
  }, "strip", z.ZodTypeAny, {
349
381
  name: string;
@@ -358,14 +390,14 @@ declare const ConfigSchema: z.ZodObject<{
358
390
  default_sorting_field?: string | undefined;
359
391
  }, {
360
392
  name: string;
361
- fields: {
393
+ fields?: {
362
394
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
363
395
  name: string;
364
396
  sort?: boolean | undefined;
365
397
  facet?: boolean | undefined;
366
398
  index?: boolean | undefined;
367
399
  optional?: boolean | undefined;
368
- }[];
400
+ }[] | undefined;
369
401
  default_sorting_field?: string | undefined;
370
402
  }>;
371
403
  }, "strip", z.ZodTypeAny, {
@@ -416,14 +448,14 @@ declare const ConfigSchema: z.ZodObject<{
416
448
  };
417
449
  collection: {
418
450
  name: string;
419
- fields: {
451
+ fields?: {
420
452
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
421
453
  name: string;
422
454
  sort?: boolean | undefined;
423
455
  facet?: boolean | undefined;
424
456
  index?: boolean | undefined;
425
457
  optional?: boolean | undefined;
426
- }[];
458
+ }[] | undefined;
427
459
  default_sorting_field?: string | undefined;
428
460
  };
429
461
  }>;
@@ -443,10 +475,6 @@ type Config = z.infer<typeof ConfigSchema>;
443
475
  * @throws {ZodError} If validation fails
444
476
  */
445
477
  declare function validateConfig(config: unknown): Config;
446
- /**
447
- * Default collection fields that should be included
448
- */
449
- declare const DEFAULT_COLLECTION_FIELDS: CollectionField[];
450
478
  /**
451
479
  * Creates a default configuration object
452
480
  * @param ghostUrl The URL of the Ghost instance
package/dist/index.js CHANGED
@@ -75,47 +75,6 @@ var REQUIRED_FIELDS = {
75
75
  published_at: { type: "int64", description: "Post publication timestamp" },
76
76
  updated_at: { type: "int64", description: "Post last update timestamp" }
77
77
  };
78
- var CollectionConfigSchema = import_zod.z.object({
79
- name: import_zod.z.string().min(1, "Collection name cannot be empty"),
80
- fields: import_zod.z.array(CollectionFieldSchema).min(1, "At least one field must be defined").refine(
81
- (fields) => {
82
- const missingOrInvalidFields = Object.entries(REQUIRED_FIELDS).filter(([fieldName, spec]) => {
83
- const field = fields.find((f) => f.name === fieldName);
84
- return !field || field.type !== spec.type || field.optional === true;
85
- });
86
- if (missingOrInvalidFields.length > 0) {
87
- const errors = missingOrInvalidFields.map(([fieldName, spec]) => {
88
- const field = fields.find((f) => f.name === fieldName);
89
- if (!field) {
90
- return `Missing required field "${fieldName}" (${spec.description})`;
91
- }
92
- if (field.type !== spec.type) {
93
- return `Field "${fieldName}" must be of type "${spec.type}" (${spec.description})`;
94
- }
95
- if (field.optional === true) {
96
- return `Field "${fieldName}" cannot be optional (${spec.description})`;
97
- }
98
- return `Invalid configuration for "${fieldName}"`;
99
- });
100
- throw new Error(`Invalid collection configuration:
101
- - ${errors.join("\n- ")}`);
102
- }
103
- return true;
104
- },
105
- {
106
- message: "Collection configuration is invalid"
107
- }
108
- ),
109
- default_sorting_field: import_zod.z.string().optional()
110
- });
111
- var ConfigSchema = import_zod.z.object({
112
- ghost: GhostConfigSchema,
113
- typesense: TypesenseConfigSchema,
114
- collection: CollectionConfigSchema
115
- });
116
- function validateConfig(config) {
117
- return ConfigSchema.parse(config);
118
- }
119
78
  var DEFAULT_COLLECTION_FIELDS = [
120
79
  { name: "id", type: "string", optional: false },
121
80
  { name: "title", type: "string", index: true, sort: true, optional: false },
@@ -129,6 +88,38 @@ var DEFAULT_COLLECTION_FIELDS = [
129
88
  { name: "tags", type: "string[]", facet: true, optional: true },
130
89
  { name: "authors", type: "string[]", facet: true, optional: true }
131
90
  ];
91
+ var CollectionConfigSchema = import_zod.z.object({
92
+ name: import_zod.z.string().min(1, "Collection name cannot be empty"),
93
+ fields: import_zod.z.array(CollectionFieldSchema).optional().transform((fields) => fields || DEFAULT_COLLECTION_FIELDS).transform((fields) => {
94
+ const fieldMap = new Map(fields.map((f) => [f.name, f]));
95
+ Object.entries(REQUIRED_FIELDS).forEach(([fieldName, spec]) => {
96
+ const existingField = fieldMap.get(fieldName);
97
+ if (!existingField) {
98
+ const defaultField = DEFAULT_COLLECTION_FIELDS.find((f) => f.name === fieldName);
99
+ if (defaultField) {
100
+ fieldMap.set(fieldName, defaultField);
101
+ }
102
+ } else {
103
+ if (existingField.type !== spec.type) {
104
+ throw new Error(`Field "${fieldName}" must be of type "${spec.type}" (${spec.description})`);
105
+ }
106
+ if (existingField.optional === true) {
107
+ throw new Error(`Field "${fieldName}" cannot be optional (${spec.description})`);
108
+ }
109
+ }
110
+ });
111
+ return Array.from(fieldMap.values());
112
+ }),
113
+ default_sorting_field: import_zod.z.string().optional()
114
+ });
115
+ var ConfigSchema = import_zod.z.object({
116
+ ghost: GhostConfigSchema,
117
+ typesense: TypesenseConfigSchema,
118
+ collection: CollectionConfigSchema
119
+ });
120
+ function validateConfig(config) {
121
+ return ConfigSchema.parse(config);
122
+ }
132
123
  function createDefaultConfig(ghostUrl, ghostKey, typesenseHost, typesenseApiKey, collectionName = "posts") {
133
124
  const cleanedHost = cleanUrl(typesenseHost);
134
125
  return {
package/dist/index.mjs CHANGED
@@ -42,47 +42,6 @@ var REQUIRED_FIELDS = {
42
42
  published_at: { type: "int64", description: "Post publication timestamp" },
43
43
  updated_at: { type: "int64", description: "Post last update timestamp" }
44
44
  };
45
- var CollectionConfigSchema = z.object({
46
- name: z.string().min(1, "Collection name cannot be empty"),
47
- fields: z.array(CollectionFieldSchema).min(1, "At least one field must be defined").refine(
48
- (fields) => {
49
- const missingOrInvalidFields = Object.entries(REQUIRED_FIELDS).filter(([fieldName, spec]) => {
50
- const field = fields.find((f) => f.name === fieldName);
51
- return !field || field.type !== spec.type || field.optional === true;
52
- });
53
- if (missingOrInvalidFields.length > 0) {
54
- const errors = missingOrInvalidFields.map(([fieldName, spec]) => {
55
- const field = fields.find((f) => f.name === fieldName);
56
- if (!field) {
57
- return `Missing required field "${fieldName}" (${spec.description})`;
58
- }
59
- if (field.type !== spec.type) {
60
- return `Field "${fieldName}" must be of type "${spec.type}" (${spec.description})`;
61
- }
62
- if (field.optional === true) {
63
- return `Field "${fieldName}" cannot be optional (${spec.description})`;
64
- }
65
- return `Invalid configuration for "${fieldName}"`;
66
- });
67
- throw new Error(`Invalid collection configuration:
68
- - ${errors.join("\n- ")}`);
69
- }
70
- return true;
71
- },
72
- {
73
- message: "Collection configuration is invalid"
74
- }
75
- ),
76
- default_sorting_field: z.string().optional()
77
- });
78
- var ConfigSchema = z.object({
79
- ghost: GhostConfigSchema,
80
- typesense: TypesenseConfigSchema,
81
- collection: CollectionConfigSchema
82
- });
83
- function validateConfig(config) {
84
- return ConfigSchema.parse(config);
85
- }
86
45
  var DEFAULT_COLLECTION_FIELDS = [
87
46
  { name: "id", type: "string", optional: false },
88
47
  { name: "title", type: "string", index: true, sort: true, optional: false },
@@ -96,6 +55,38 @@ var DEFAULT_COLLECTION_FIELDS = [
96
55
  { name: "tags", type: "string[]", facet: true, optional: true },
97
56
  { name: "authors", type: "string[]", facet: true, optional: true }
98
57
  ];
58
+ var CollectionConfigSchema = z.object({
59
+ name: z.string().min(1, "Collection name cannot be empty"),
60
+ fields: z.array(CollectionFieldSchema).optional().transform((fields) => fields || DEFAULT_COLLECTION_FIELDS).transform((fields) => {
61
+ const fieldMap = new Map(fields.map((f) => [f.name, f]));
62
+ Object.entries(REQUIRED_FIELDS).forEach(([fieldName, spec]) => {
63
+ const existingField = fieldMap.get(fieldName);
64
+ if (!existingField) {
65
+ const defaultField = DEFAULT_COLLECTION_FIELDS.find((f) => f.name === fieldName);
66
+ if (defaultField) {
67
+ fieldMap.set(fieldName, defaultField);
68
+ }
69
+ } else {
70
+ if (existingField.type !== spec.type) {
71
+ throw new Error(`Field "${fieldName}" must be of type "${spec.type}" (${spec.description})`);
72
+ }
73
+ if (existingField.optional === true) {
74
+ throw new Error(`Field "${fieldName}" cannot be optional (${spec.description})`);
75
+ }
76
+ }
77
+ });
78
+ return Array.from(fieldMap.values());
79
+ }),
80
+ default_sorting_field: z.string().optional()
81
+ });
82
+ var ConfigSchema = z.object({
83
+ ghost: GhostConfigSchema,
84
+ typesense: TypesenseConfigSchema,
85
+ collection: CollectionConfigSchema
86
+ });
87
+ function validateConfig(config) {
88
+ return ConfigSchema.parse(config);
89
+ }
99
90
  function createDefaultConfig(ghostUrl, ghostKey, typesenseHost, typesenseApiKey, collectionName = "posts") {
100
91
  const cleanedHost = cleanUrl(typesenseHost);
101
92
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicpages/ghost-typesense-config",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Configuration types and utilities for Ghost-Typesense integration",
5
5
  "author": "MagicPages",
6
6
  "license": "MIT",
@@ -40,4 +40,4 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  }
43
- }
43
+ }