@magicpages/ghost-typesense-config 1.0.1 → 1.1.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @magicpages/ghost-typesense-config
2
2
 
3
- Configuration types and utilities for Ghost-Typesense integration. This package provides type-safe configuration management for Ghost CMS and Typesense integration.
3
+ Configuration types and utilities for Ghost-Typesense integration.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,8 +11,19 @@ npm install @magicpages/ghost-typesense-config
11
11
  ## Usage
12
12
 
13
13
  ```typescript
14
+ import { createDefaultConfig } from '@magicpages/ghost-typesense-config';
15
+
16
+ // Create a config with default schema
17
+ const config = createDefaultConfig(
18
+ 'https://your-ghost-blog.com',
19
+ 'your-content-api-key',
20
+ 'your-typesense-host',
21
+ 'your-typesense-api-key',
22
+ 'ghost' // collection name
23
+ );
24
+
25
+ // Or create a custom config
14
26
  import type { Config } from '@magicpages/ghost-typesense-config';
15
- import { validateConfig } from '@magicpages/ghost-typesense-config';
16
27
 
17
28
  const config: Config = {
18
29
  ghost: {
@@ -26,105 +37,37 @@ const config: Config = {
26
37
  port: 443,
27
38
  protocol: 'https'
28
39
  }],
29
- apiKey: 'your-typesense-api-key',
30
- connectionTimeoutSeconds: 10,
31
- retryIntervalSeconds: 0.1
40
+ apiKey: 'your-typesense-api-key'
32
41
  },
33
42
  collection: {
34
- name: 'posts',
35
- fields: [
36
- { name: 'id', type: 'string' },
37
- { name: 'title', type: 'string', index: true, sort: true },
38
- { name: 'slug', type: 'string', index: true },
39
- { name: 'html', type: 'string', index: true },
40
- { name: 'excerpt', type: 'string', index: true },
41
- { name: 'feature_image', type: 'string', index: false, optional: true },
42
- { name: 'published_at', type: 'int64', sort: true },
43
- { name: 'updated_at', type: 'int64', sort: true },
44
- { name: 'tags', type: 'string[]', facet: true, optional: true },
45
- { name: 'authors', type: 'string[]', facet: true, optional: true }
46
- ]
43
+ name: 'ghost'
47
44
  }
48
45
  };
49
-
50
- // Validate configuration
51
- const result = validateConfig(config);
52
- if (!result.success) {
53
- console.error('Invalid configuration:', result.error);
54
- }
55
46
  ```
56
47
 
57
- ## Type Definitions
58
-
59
- ### `Config`
60
-
61
- The main configuration type that includes all settings for Ghost and Typesense integration.
48
+ ## Types
62
49
 
63
50
  ```typescript
64
51
  interface Config {
65
- ghost: GhostConfig;
66
- typesense: TypesenseConfig;
67
- collection: CollectionConfig;
68
- }
69
- ```
70
-
71
- ### `GhostConfig`
72
-
73
- Configuration for connecting to Ghost CMS.
74
-
75
- ```typescript
76
- interface GhostConfig {
77
- url: string;
78
- key: string;
79
- version: string;
80
- }
81
- ```
82
-
83
- ### `TypesenseConfig`
84
-
85
- Configuration for connecting to Typesense.
86
-
87
- ```typescript
88
- interface TypesenseConfig {
89
- nodes: {
90
- host: string;
91
- port: number;
92
- protocol: 'http' | 'https';
93
- }[];
94
- apiKey: string;
95
- connectionTimeoutSeconds?: number;
96
- retryIntervalSeconds?: number;
97
- }
98
- ```
99
-
100
- ### `CollectionConfig`
101
-
102
- Configuration for the Typesense collection schema.
103
-
104
- ```typescript
105
- interface CollectionConfig {
106
- name: string;
107
- fields: FieldConfig[];
108
- }
109
-
110
- interface FieldConfig {
111
- name: string;
112
- type: 'string' | 'int32' | 'int64' | 'float' | 'bool' | 'string[]' | 'int32[]' | 'int64[]' | 'float[]' | 'bool[]';
113
- index?: boolean;
114
- sort?: boolean;
115
- facet?: boolean;
116
- optional?: boolean;
52
+ ghost: {
53
+ url: string;
54
+ key: string;
55
+ version: string;
56
+ };
57
+ typesense: {
58
+ nodes: {
59
+ host: string;
60
+ port: number;
61
+ protocol: 'http' | 'https';
62
+ }[];
63
+ apiKey: string;
64
+ };
65
+ collection: {
66
+ name: string;
67
+ };
117
68
  }
118
69
  ```
119
70
 
120
- ## Validation
121
-
122
- The package uses Zod for runtime type validation of configuration objects. The `validateConfig` function returns a type-safe result that indicates whether the configuration is valid.
123
-
124
- ## TypeScript Support
125
-
126
- This package is written in TypeScript and includes full type definitions. It uses strict type checking and provides comprehensive type safety for all configuration options.
127
-
128
71
  ## License
129
72
 
130
- MIT - see the [LICENSE](../../LICENSE) file for details.
73
+ MIT © [MagicPages](https://www.magicpages.co)
package/dist/index.d.mts CHANGED
@@ -82,7 +82,7 @@ declare const TypesenseConfigSchema: z.ZodObject<{
82
82
  /**
83
83
  * Collection field configuration schema
84
84
  */
85
- declare const CollectionFieldSchema: z.ZodObject<{
85
+ declare const CollectionFieldSchema: z.ZodEffects<z.ZodObject<{
86
86
  name: z.ZodString;
87
87
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
88
88
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -103,13 +103,64 @@ declare const CollectionFieldSchema: z.ZodObject<{
103
103
  facet?: boolean | undefined;
104
104
  index?: boolean | undefined;
105
105
  optional?: boolean | undefined;
106
+ }>, {
107
+ optional: boolean;
108
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
109
+ name: string;
110
+ sort?: boolean | undefined;
111
+ facet?: boolean | undefined;
112
+ index?: boolean | undefined;
113
+ }, {
114
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
115
+ name: string;
116
+ sort?: boolean | undefined;
117
+ facet?: boolean | undefined;
118
+ index?: boolean | undefined;
119
+ optional?: boolean | undefined;
106
120
  }>;
107
121
  /**
108
- * Collection configuration schema
122
+ * Required fields that must be present in the collection
123
+ */
124
+ declare const REQUIRED_FIELDS: {
125
+ readonly id: {
126
+ readonly type: "string";
127
+ readonly description: "Unique identifier for the post";
128
+ };
129
+ readonly title: {
130
+ readonly type: "string";
131
+ readonly description: "Post title";
132
+ };
133
+ readonly url: {
134
+ readonly type: "string";
135
+ readonly description: "Full URL to the post";
136
+ };
137
+ readonly slug: {
138
+ readonly type: "string";
139
+ readonly description: "URL-friendly post slug";
140
+ };
141
+ readonly html: {
142
+ readonly type: "string";
143
+ readonly description: "Post content in HTML format";
144
+ };
145
+ readonly excerpt: {
146
+ readonly type: "string";
147
+ readonly description: "Post excerpt or summary";
148
+ };
149
+ readonly published_at: {
150
+ readonly type: "int64";
151
+ readonly description: "Post publication timestamp";
152
+ };
153
+ readonly updated_at: {
154
+ readonly type: "int64";
155
+ readonly description: "Post last update timestamp";
156
+ };
157
+ };
158
+ /**
159
+ * Collection configuration schema with strict validation
109
160
  */
110
161
  declare const CollectionConfigSchema: z.ZodObject<{
111
162
  name: z.ZodString;
112
- fields: z.ZodArray<z.ZodObject<{
163
+ fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
113
164
  name: z.ZodString;
114
165
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
115
166
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -130,17 +181,45 @@ declare const CollectionConfigSchema: z.ZodObject<{
130
181
  facet?: boolean | undefined;
131
182
  index?: boolean | undefined;
132
183
  optional?: boolean | undefined;
133
- }>, "many">;
184
+ }>, {
185
+ optional: boolean;
186
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
187
+ name: string;
188
+ sort?: boolean | undefined;
189
+ facet?: boolean | undefined;
190
+ index?: boolean | undefined;
191
+ }, {
192
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
193
+ name: string;
194
+ sort?: boolean | undefined;
195
+ facet?: boolean | undefined;
196
+ index?: boolean | undefined;
197
+ optional?: boolean | undefined;
198
+ }>, "many">, {
199
+ optional: boolean;
200
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
201
+ name: string;
202
+ sort?: boolean | undefined;
203
+ facet?: boolean | undefined;
204
+ index?: boolean | undefined;
205
+ }[], {
206
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
207
+ name: string;
208
+ sort?: boolean | undefined;
209
+ facet?: boolean | undefined;
210
+ index?: boolean | undefined;
211
+ optional?: boolean | undefined;
212
+ }[]>;
134
213
  default_sorting_field: z.ZodOptional<z.ZodString>;
135
214
  }, "strip", z.ZodTypeAny, {
136
215
  name: string;
137
216
  fields: {
217
+ optional: boolean;
138
218
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
139
219
  name: string;
140
220
  sort?: boolean | undefined;
141
221
  facet?: boolean | undefined;
142
222
  index?: boolean | undefined;
143
- optional?: boolean | undefined;
144
223
  }[];
145
224
  default_sorting_field?: string | undefined;
146
225
  }, {
@@ -215,7 +294,7 @@ declare const ConfigSchema: z.ZodObject<{
215
294
  }>;
216
295
  collection: z.ZodObject<{
217
296
  name: z.ZodString;
218
- fields: z.ZodArray<z.ZodObject<{
297
+ fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
219
298
  name: z.ZodString;
220
299
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
221
300
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -236,17 +315,45 @@ declare const ConfigSchema: z.ZodObject<{
236
315
  facet?: boolean | undefined;
237
316
  index?: boolean | undefined;
238
317
  optional?: boolean | undefined;
239
- }>, "many">;
318
+ }>, {
319
+ optional: boolean;
320
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
321
+ name: string;
322
+ sort?: boolean | undefined;
323
+ facet?: boolean | undefined;
324
+ index?: boolean | undefined;
325
+ }, {
326
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
327
+ name: string;
328
+ sort?: boolean | undefined;
329
+ facet?: boolean | undefined;
330
+ index?: boolean | undefined;
331
+ optional?: boolean | undefined;
332
+ }>, "many">, {
333
+ optional: boolean;
334
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
335
+ name: string;
336
+ sort?: boolean | undefined;
337
+ facet?: boolean | undefined;
338
+ index?: boolean | undefined;
339
+ }[], {
340
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
341
+ name: string;
342
+ sort?: boolean | undefined;
343
+ facet?: boolean | undefined;
344
+ index?: boolean | undefined;
345
+ optional?: boolean | undefined;
346
+ }[]>;
240
347
  default_sorting_field: z.ZodOptional<z.ZodString>;
241
348
  }, "strip", z.ZodTypeAny, {
242
349
  name: string;
243
350
  fields: {
351
+ optional: boolean;
244
352
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
245
353
  name: string;
246
354
  sort?: boolean | undefined;
247
355
  facet?: boolean | undefined;
248
356
  index?: boolean | undefined;
249
- optional?: boolean | undefined;
250
357
  }[];
251
358
  default_sorting_field?: string | undefined;
252
359
  }, {
@@ -281,12 +388,12 @@ declare const ConfigSchema: z.ZodObject<{
281
388
  collection: {
282
389
  name: string;
283
390
  fields: {
391
+ optional: boolean;
284
392
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
285
393
  name: string;
286
394
  sort?: boolean | undefined;
287
395
  facet?: boolean | undefined;
288
396
  index?: boolean | undefined;
289
- optional?: boolean | undefined;
290
397
  }[];
291
398
  default_sorting_field?: string | undefined;
292
399
  };
@@ -351,4 +458,4 @@ declare const DEFAULT_COLLECTION_FIELDS: CollectionField[];
351
458
  */
352
459
  declare function createDefaultConfig(ghostUrl: string, ghostKey: string, typesenseHost: string, typesenseApiKey: string, collectionName?: string): Config;
353
460
 
354
- export { type CollectionConfig, CollectionConfigSchema, type CollectionField, CollectionFieldSchema, type Config, ConfigSchema, DEFAULT_COLLECTION_FIELDS, type GhostConfig, GhostConfigSchema, type TypesenseConfig, TypesenseConfigSchema, type TypesenseNode, TypesenseNodeSchema, createDefaultConfig, validateConfig };
461
+ export { type CollectionConfig, CollectionConfigSchema, type CollectionField, CollectionFieldSchema, type Config, ConfigSchema, DEFAULT_COLLECTION_FIELDS, type GhostConfig, GhostConfigSchema, REQUIRED_FIELDS, type TypesenseConfig, TypesenseConfigSchema, type TypesenseNode, TypesenseNodeSchema, createDefaultConfig, validateConfig };
package/dist/index.d.ts CHANGED
@@ -82,7 +82,7 @@ declare const TypesenseConfigSchema: z.ZodObject<{
82
82
  /**
83
83
  * Collection field configuration schema
84
84
  */
85
- declare const CollectionFieldSchema: z.ZodObject<{
85
+ declare const CollectionFieldSchema: z.ZodEffects<z.ZodObject<{
86
86
  name: z.ZodString;
87
87
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
88
88
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -103,13 +103,64 @@ declare const CollectionFieldSchema: z.ZodObject<{
103
103
  facet?: boolean | undefined;
104
104
  index?: boolean | undefined;
105
105
  optional?: boolean | undefined;
106
+ }>, {
107
+ optional: boolean;
108
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
109
+ name: string;
110
+ sort?: boolean | undefined;
111
+ facet?: boolean | undefined;
112
+ index?: boolean | undefined;
113
+ }, {
114
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
115
+ name: string;
116
+ sort?: boolean | undefined;
117
+ facet?: boolean | undefined;
118
+ index?: boolean | undefined;
119
+ optional?: boolean | undefined;
106
120
  }>;
107
121
  /**
108
- * Collection configuration schema
122
+ * Required fields that must be present in the collection
123
+ */
124
+ declare const REQUIRED_FIELDS: {
125
+ readonly id: {
126
+ readonly type: "string";
127
+ readonly description: "Unique identifier for the post";
128
+ };
129
+ readonly title: {
130
+ readonly type: "string";
131
+ readonly description: "Post title";
132
+ };
133
+ readonly url: {
134
+ readonly type: "string";
135
+ readonly description: "Full URL to the post";
136
+ };
137
+ readonly slug: {
138
+ readonly type: "string";
139
+ readonly description: "URL-friendly post slug";
140
+ };
141
+ readonly html: {
142
+ readonly type: "string";
143
+ readonly description: "Post content in HTML format";
144
+ };
145
+ readonly excerpt: {
146
+ readonly type: "string";
147
+ readonly description: "Post excerpt or summary";
148
+ };
149
+ readonly published_at: {
150
+ readonly type: "int64";
151
+ readonly description: "Post publication timestamp";
152
+ };
153
+ readonly updated_at: {
154
+ readonly type: "int64";
155
+ readonly description: "Post last update timestamp";
156
+ };
157
+ };
158
+ /**
159
+ * Collection configuration schema with strict validation
109
160
  */
110
161
  declare const CollectionConfigSchema: z.ZodObject<{
111
162
  name: z.ZodString;
112
- fields: z.ZodArray<z.ZodObject<{
163
+ fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
113
164
  name: z.ZodString;
114
165
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
115
166
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -130,17 +181,45 @@ declare const CollectionConfigSchema: z.ZodObject<{
130
181
  facet?: boolean | undefined;
131
182
  index?: boolean | undefined;
132
183
  optional?: boolean | undefined;
133
- }>, "many">;
184
+ }>, {
185
+ optional: boolean;
186
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
187
+ name: string;
188
+ sort?: boolean | undefined;
189
+ facet?: boolean | undefined;
190
+ index?: boolean | undefined;
191
+ }, {
192
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
193
+ name: string;
194
+ sort?: boolean | undefined;
195
+ facet?: boolean | undefined;
196
+ index?: boolean | undefined;
197
+ optional?: boolean | undefined;
198
+ }>, "many">, {
199
+ optional: boolean;
200
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
201
+ name: string;
202
+ sort?: boolean | undefined;
203
+ facet?: boolean | undefined;
204
+ index?: boolean | undefined;
205
+ }[], {
206
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
207
+ name: string;
208
+ sort?: boolean | undefined;
209
+ facet?: boolean | undefined;
210
+ index?: boolean | undefined;
211
+ optional?: boolean | undefined;
212
+ }[]>;
134
213
  default_sorting_field: z.ZodOptional<z.ZodString>;
135
214
  }, "strip", z.ZodTypeAny, {
136
215
  name: string;
137
216
  fields: {
217
+ optional: boolean;
138
218
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
139
219
  name: string;
140
220
  sort?: boolean | undefined;
141
221
  facet?: boolean | undefined;
142
222
  index?: boolean | undefined;
143
- optional?: boolean | undefined;
144
223
  }[];
145
224
  default_sorting_field?: string | undefined;
146
225
  }, {
@@ -215,7 +294,7 @@ declare const ConfigSchema: z.ZodObject<{
215
294
  }>;
216
295
  collection: z.ZodObject<{
217
296
  name: z.ZodString;
218
- fields: z.ZodArray<z.ZodObject<{
297
+ fields: z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodObject<{
219
298
  name: z.ZodString;
220
299
  type: z.ZodEnum<["string", "int32", "int64", "float", "bool", "string[]", "int32[]", "int64[]", "float[]", "bool[]"]>;
221
300
  facet: z.ZodOptional<z.ZodBoolean>;
@@ -236,17 +315,45 @@ declare const ConfigSchema: z.ZodObject<{
236
315
  facet?: boolean | undefined;
237
316
  index?: boolean | undefined;
238
317
  optional?: boolean | undefined;
239
- }>, "many">;
318
+ }>, {
319
+ optional: boolean;
320
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
321
+ name: string;
322
+ sort?: boolean | undefined;
323
+ facet?: boolean | undefined;
324
+ index?: boolean | undefined;
325
+ }, {
326
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
327
+ name: string;
328
+ sort?: boolean | undefined;
329
+ facet?: boolean | undefined;
330
+ index?: boolean | undefined;
331
+ optional?: boolean | undefined;
332
+ }>, "many">, {
333
+ optional: boolean;
334
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
335
+ name: string;
336
+ sort?: boolean | undefined;
337
+ facet?: boolean | undefined;
338
+ index?: boolean | undefined;
339
+ }[], {
340
+ type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
341
+ name: string;
342
+ sort?: boolean | undefined;
343
+ facet?: boolean | undefined;
344
+ index?: boolean | undefined;
345
+ optional?: boolean | undefined;
346
+ }[]>;
240
347
  default_sorting_field: z.ZodOptional<z.ZodString>;
241
348
  }, "strip", z.ZodTypeAny, {
242
349
  name: string;
243
350
  fields: {
351
+ optional: boolean;
244
352
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
245
353
  name: string;
246
354
  sort?: boolean | undefined;
247
355
  facet?: boolean | undefined;
248
356
  index?: boolean | undefined;
249
- optional?: boolean | undefined;
250
357
  }[];
251
358
  default_sorting_field?: string | undefined;
252
359
  }, {
@@ -281,12 +388,12 @@ declare const ConfigSchema: z.ZodObject<{
281
388
  collection: {
282
389
  name: string;
283
390
  fields: {
391
+ optional: boolean;
284
392
  type: "string" | "float" | "int32" | "int64" | "bool" | "string[]" | "int32[]" | "int64[]" | "float[]" | "bool[]";
285
393
  name: string;
286
394
  sort?: boolean | undefined;
287
395
  facet?: boolean | undefined;
288
396
  index?: boolean | undefined;
289
- optional?: boolean | undefined;
290
397
  }[];
291
398
  default_sorting_field?: string | undefined;
292
399
  };
@@ -351,4 +458,4 @@ declare const DEFAULT_COLLECTION_FIELDS: CollectionField[];
351
458
  */
352
459
  declare function createDefaultConfig(ghostUrl: string, ghostKey: string, typesenseHost: string, typesenseApiKey: string, collectionName?: string): Config;
353
460
 
354
- export { type CollectionConfig, CollectionConfigSchema, type CollectionField, CollectionFieldSchema, type Config, ConfigSchema, DEFAULT_COLLECTION_FIELDS, type GhostConfig, GhostConfigSchema, type TypesenseConfig, TypesenseConfigSchema, type TypesenseNode, TypesenseNodeSchema, createDefaultConfig, validateConfig };
461
+ export { type CollectionConfig, CollectionConfigSchema, type CollectionField, CollectionFieldSchema, type Config, ConfigSchema, DEFAULT_COLLECTION_FIELDS, type GhostConfig, GhostConfigSchema, REQUIRED_FIELDS, type TypesenseConfig, TypesenseConfigSchema, type TypesenseNode, TypesenseNodeSchema, createDefaultConfig, validateConfig };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  ConfigSchema: () => ConfigSchema,
26
26
  DEFAULT_COLLECTION_FIELDS: () => DEFAULT_COLLECTION_FIELDS,
27
27
  GhostConfigSchema: () => GhostConfigSchema,
28
+ REQUIRED_FIELDS: () => REQUIRED_FIELDS,
28
29
  TypesenseConfigSchema: () => TypesenseConfigSchema,
29
30
  TypesenseNodeSchema: () => TypesenseNodeSchema,
30
31
  createDefaultConfig: () => createDefaultConfig,
@@ -56,10 +57,51 @@ var CollectionFieldSchema = import_zod.z.object({
56
57
  index: import_zod.z.boolean().optional(),
57
58
  optional: import_zod.z.boolean().optional(),
58
59
  sort: import_zod.z.boolean().optional()
59
- });
60
+ }).transform((data) => ({
61
+ ...data,
62
+ optional: data.optional ?? false
63
+ }));
64
+ var REQUIRED_FIELDS = {
65
+ id: { type: "string", description: "Unique identifier for the post" },
66
+ title: { type: "string", description: "Post title" },
67
+ url: { type: "string", description: "Full URL to the post" },
68
+ slug: { type: "string", description: "URL-friendly post slug" },
69
+ html: { type: "string", description: "Post content in HTML format" },
70
+ excerpt: { type: "string", description: "Post excerpt or summary" },
71
+ published_at: { type: "int64", description: "Post publication timestamp" },
72
+ updated_at: { type: "int64", description: "Post last update timestamp" }
73
+ };
60
74
  var CollectionConfigSchema = import_zod.z.object({
61
- name: import_zod.z.string(),
62
- fields: import_zod.z.array(CollectionFieldSchema).min(1),
75
+ name: import_zod.z.string().min(1, "Collection name cannot be empty"),
76
+ fields: import_zod.z.array(CollectionFieldSchema).min(1, "At least one field must be defined").refine(
77
+ (fields) => {
78
+ const missingOrInvalidFields = Object.entries(REQUIRED_FIELDS).filter(([fieldName, spec]) => {
79
+ const field = fields.find((f) => f.name === fieldName);
80
+ return !field || field.type !== spec.type || field.optional === true;
81
+ });
82
+ if (missingOrInvalidFields.length > 0) {
83
+ const errors = missingOrInvalidFields.map(([fieldName, spec]) => {
84
+ const field = fields.find((f) => f.name === fieldName);
85
+ if (!field) {
86
+ return `Missing required field "${fieldName}" (${spec.description})`;
87
+ }
88
+ if (field.type !== spec.type) {
89
+ return `Field "${fieldName}" must be of type "${spec.type}" (${spec.description})`;
90
+ }
91
+ if (field.optional === true) {
92
+ return `Field "${fieldName}" cannot be optional (${spec.description})`;
93
+ }
94
+ return `Invalid configuration for "${fieldName}"`;
95
+ });
96
+ throw new Error(`Invalid collection configuration:
97
+ - ${errors.join("\n- ")}`);
98
+ }
99
+ return true;
100
+ },
101
+ {
102
+ message: "Collection configuration is invalid"
103
+ }
104
+ ),
63
105
  default_sorting_field: import_zod.z.string().optional()
64
106
  });
65
107
  var ConfigSchema = import_zod.z.object({
@@ -71,14 +113,15 @@ function validateConfig(config) {
71
113
  return ConfigSchema.parse(config);
72
114
  }
73
115
  var DEFAULT_COLLECTION_FIELDS = [
74
- { name: "id", type: "string" },
75
- { name: "title", type: "string" },
76
- { name: "slug", type: "string" },
77
- { name: "html", type: "string" },
78
- { name: "excerpt", type: "string" },
79
- { name: "feature_image", type: "string", optional: true },
80
- { name: "published_at", type: "int64" },
81
- { name: "updated_at", type: "int64" },
116
+ { name: "id", type: "string", optional: false },
117
+ { name: "title", type: "string", index: true, sort: true, optional: false },
118
+ { name: "url", type: "string", index: true, optional: false },
119
+ { name: "slug", type: "string", index: true, optional: false },
120
+ { name: "html", type: "string", index: true, optional: false },
121
+ { name: "excerpt", type: "string", index: true, optional: false },
122
+ { name: "feature_image", type: "string", index: false, optional: true },
123
+ { name: "published_at", type: "int64", sort: true, optional: false },
124
+ { name: "updated_at", type: "int64", sort: true, optional: false },
82
125
  { name: "tags", type: "string[]", facet: true, optional: true },
83
126
  { name: "authors", type: "string[]", facet: true, optional: true }
84
127
  ];
@@ -112,6 +155,7 @@ function createDefaultConfig(ghostUrl, ghostKey, typesenseHost, typesenseApiKey,
112
155
  ConfigSchema,
113
156
  DEFAULT_COLLECTION_FIELDS,
114
157
  GhostConfigSchema,
158
+ REQUIRED_FIELDS,
115
159
  TypesenseConfigSchema,
116
160
  TypesenseNodeSchema,
117
161
  createDefaultConfig,
package/dist/index.mjs CHANGED
@@ -24,10 +24,51 @@ var CollectionFieldSchema = z.object({
24
24
  index: z.boolean().optional(),
25
25
  optional: z.boolean().optional(),
26
26
  sort: z.boolean().optional()
27
- });
27
+ }).transform((data) => ({
28
+ ...data,
29
+ optional: data.optional ?? false
30
+ }));
31
+ var REQUIRED_FIELDS = {
32
+ id: { type: "string", description: "Unique identifier for the post" },
33
+ title: { type: "string", description: "Post title" },
34
+ url: { type: "string", description: "Full URL to the post" },
35
+ slug: { type: "string", description: "URL-friendly post slug" },
36
+ html: { type: "string", description: "Post content in HTML format" },
37
+ excerpt: { type: "string", description: "Post excerpt or summary" },
38
+ published_at: { type: "int64", description: "Post publication timestamp" },
39
+ updated_at: { type: "int64", description: "Post last update timestamp" }
40
+ };
28
41
  var CollectionConfigSchema = z.object({
29
- name: z.string(),
30
- fields: z.array(CollectionFieldSchema).min(1),
42
+ name: z.string().min(1, "Collection name cannot be empty"),
43
+ fields: z.array(CollectionFieldSchema).min(1, "At least one field must be defined").refine(
44
+ (fields) => {
45
+ const missingOrInvalidFields = Object.entries(REQUIRED_FIELDS).filter(([fieldName, spec]) => {
46
+ const field = fields.find((f) => f.name === fieldName);
47
+ return !field || field.type !== spec.type || field.optional === true;
48
+ });
49
+ if (missingOrInvalidFields.length > 0) {
50
+ const errors = missingOrInvalidFields.map(([fieldName, spec]) => {
51
+ const field = fields.find((f) => f.name === fieldName);
52
+ if (!field) {
53
+ return `Missing required field "${fieldName}" (${spec.description})`;
54
+ }
55
+ if (field.type !== spec.type) {
56
+ return `Field "${fieldName}" must be of type "${spec.type}" (${spec.description})`;
57
+ }
58
+ if (field.optional === true) {
59
+ return `Field "${fieldName}" cannot be optional (${spec.description})`;
60
+ }
61
+ return `Invalid configuration for "${fieldName}"`;
62
+ });
63
+ throw new Error(`Invalid collection configuration:
64
+ - ${errors.join("\n- ")}`);
65
+ }
66
+ return true;
67
+ },
68
+ {
69
+ message: "Collection configuration is invalid"
70
+ }
71
+ ),
31
72
  default_sorting_field: z.string().optional()
32
73
  });
33
74
  var ConfigSchema = z.object({
@@ -39,14 +80,15 @@ function validateConfig(config) {
39
80
  return ConfigSchema.parse(config);
40
81
  }
41
82
  var DEFAULT_COLLECTION_FIELDS = [
42
- { name: "id", type: "string" },
43
- { name: "title", type: "string" },
44
- { name: "slug", type: "string" },
45
- { name: "html", type: "string" },
46
- { name: "excerpt", type: "string" },
47
- { name: "feature_image", type: "string", optional: true },
48
- { name: "published_at", type: "int64" },
49
- { name: "updated_at", type: "int64" },
83
+ { name: "id", type: "string", optional: false },
84
+ { name: "title", type: "string", index: true, sort: true, optional: false },
85
+ { name: "url", type: "string", index: true, optional: false },
86
+ { name: "slug", type: "string", index: true, optional: false },
87
+ { name: "html", type: "string", index: true, optional: false },
88
+ { name: "excerpt", type: "string", index: true, optional: false },
89
+ { name: "feature_image", type: "string", index: false, optional: true },
90
+ { name: "published_at", type: "int64", sort: true, optional: false },
91
+ { name: "updated_at", type: "int64", sort: true, optional: false },
50
92
  { name: "tags", type: "string[]", facet: true, optional: true },
51
93
  { name: "authors", type: "string[]", facet: true, optional: true }
52
94
  ];
@@ -79,6 +121,7 @@ export {
79
121
  ConfigSchema,
80
122
  DEFAULT_COLLECTION_FIELDS,
81
123
  GhostConfigSchema,
124
+ REQUIRED_FIELDS,
82
125
  TypesenseConfigSchema,
83
126
  TypesenseNodeSchema,
84
127
  createDefaultConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicpages/ghost-typesense-config",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Configuration types and utilities for Ghost-Typesense integration",
5
5
  "author": "MagicPages",
6
6
  "license": "MIT",