@nextsparkjs/core 0.1.0-beta.65 → 0.1.0-beta.67

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.
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Patterns Service Types
3
+ *
4
+ * Type definitions for the patterns entity and pattern references.
5
+ * Patterns is a team-scoped entity (shared: true) - all team members see the same patterns.
6
+ */
7
+
8
+ import type { BlockInstance } from '../../types/blocks'
9
+
10
+ /**
11
+ * Pattern status values
12
+ */
13
+ export type PatternStatus = 'draft' | 'published'
14
+
15
+ /**
16
+ * Pattern entity
17
+ *
18
+ * Represents a reusable block composition.
19
+ * System fields (id, userId, teamId, createdAt, updatedAt) are always included.
20
+ */
21
+ export interface Pattern {
22
+ id: string
23
+ userId: string
24
+ teamId: string
25
+ title: string
26
+ slug: string
27
+ blocks: BlockInstance[]
28
+ status: PatternStatus
29
+ description?: string
30
+ createdAt: string
31
+ updatedAt: string
32
+ }
33
+
34
+ /**
35
+ * Input for creating a new pattern
36
+ */
37
+ export interface CreatePatternInput {
38
+ title: string
39
+ slug: string
40
+ blocks?: BlockInstance[]
41
+ status?: PatternStatus
42
+ description?: string
43
+ }
44
+
45
+ /**
46
+ * Input for updating an existing pattern
47
+ */
48
+ export interface UpdatePatternInput {
49
+ title?: string
50
+ slug?: string
51
+ blocks?: BlockInstance[]
52
+ status?: PatternStatus
53
+ description?: string
54
+ }
55
+
56
+ /**
57
+ * Pattern reference stored in page/post blocks array
58
+ *
59
+ * This is NOT a real block - it's a reference that gets resolved at render time.
60
+ * The pattern's actual blocks are fetched and expanded when rendering the page.
61
+ *
62
+ * @example
63
+ * // In a page's blocks array:
64
+ * [
65
+ * { id: 'block-1', blockSlug: 'hero', props: {...} },
66
+ * { type: 'pattern', ref: 'pattern-uuid', id: 'instance-1' }, // Pattern reference
67
+ * { id: 'block-2', blockSlug: 'cta', props: {...} }
68
+ * ]
69
+ */
70
+ export interface PatternReference {
71
+ type: 'pattern'
72
+ ref: string // Pattern UUID to resolve
73
+ id: string // Unique instance ID for this reference
74
+ }
75
+
76
+ /**
77
+ * Type guard to check if a block is a pattern reference
78
+ *
79
+ * @param block - Block or pattern reference to check
80
+ * @returns True if block is a pattern reference
81
+ *
82
+ * @example
83
+ * if (isPatternReference(block)) {
84
+ * // Handle pattern reference
85
+ * const pattern = await PatternsService.getById(block.ref, userId)
86
+ * } else {
87
+ * // Handle regular block
88
+ * renderBlock(block)
89
+ * }
90
+ */
91
+ export function isPatternReference(block: unknown): block is PatternReference {
92
+ return (
93
+ typeof block === 'object' &&
94
+ block !== null &&
95
+ (block as Record<string, unknown>).type === 'pattern' &&
96
+ typeof (block as Record<string, unknown>).ref === 'string' &&
97
+ typeof (block as Record<string, unknown>).id === 'string'
98
+ )
99
+ }
100
+
101
+ /**
102
+ * Options for listing patterns
103
+ */
104
+ export interface PatternListOptions {
105
+ limit?: number
106
+ offset?: number
107
+ status?: PatternStatus
108
+ orderBy?: 'title' | 'slug' | 'status' | 'createdAt' | 'updatedAt'
109
+ orderDir?: 'asc' | 'desc'
110
+ }
111
+
112
+ /**
113
+ * Result of listing patterns with pagination
114
+ */
115
+ export interface PatternListResult {
116
+ data: Pattern[]
117
+ total: number
118
+ }