@beechcms/cli 0.6.0-preview.3 → 0.6.0-preview.4
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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +1 -0
- package/coverage/coverage-summary.json +3 -0
- package/dist/index.js +445 -249
- package/package.json +3 -2
- package/src/commands/deploy.ts +126 -126
- package/src/commands/generate-types.ts +65 -0
- package/src/commands/init.ts +599 -599
- package/src/commands/onboard.ts +32 -32
- package/src/commands/schema-diff.ts +78 -0
- package/src/commands/seed-create.ts +192 -192
- package/src/commands/seed-load.ts +206 -235
- package/src/commands/update.ts +54 -54
- package/src/commands/validate.ts +80 -80
- package/src/index.ts +24 -20
- package/src/lib/migration-writer.ts +106 -0
- package/src/lib/schema-diff.ts +175 -150
- package/src/lib/wrangler.ts +129 -129
- package/src/test/generate-types.test.ts +58 -0
- package/src/test/schema-diff.test.ts +232 -0
- package/src/test/seed-load.test.ts +158 -158
- package/src/test/validate.test.ts +261 -261
- package/tsconfig.json +16 -16
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +33 -33
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -116
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/validate.ts.html +0 -325
- package/coverage/lcov.info +0 -80
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/validate.ts.html +0 -325
- package/dist/commands/seed-load.d.ts +0 -8
- package/dist/commands/seed-load.d.ts.map +0 -1
- package/dist/commands/seed-load.js +0 -89
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/schema-diff.d.ts +0 -15
- package/dist/lib/schema-diff.d.ts.map +0 -1
- package/dist/lib/schema-diff.js +0 -37
- package/dist/lib/wrangler.d.ts +0 -17
- package/dist/lib/wrangler.d.ts.map +0 -1
- package/dist/lib/wrangler.js +0 -65
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<!doctype html>
|
|
3
|
-
<html lang="en">
|
|
4
|
-
|
|
5
|
-
<head>
|
|
6
|
-
<title>Code coverage report for validate.ts</title>
|
|
7
|
-
<meta charset="utf-8" />
|
|
8
|
-
<link rel="stylesheet" href="prettify.css" />
|
|
9
|
-
<link rel="stylesheet" href="base.css" />
|
|
10
|
-
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
|
11
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
-
<style type='text/css'>
|
|
13
|
-
.coverage-summary .sorter {
|
|
14
|
-
background-image: url(sort-arrow-sprite.png);
|
|
15
|
-
}
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<div class='wrapper'>
|
|
21
|
-
<div class='pad1'>
|
|
22
|
-
<h1><a href="index.html">All files</a> validate.ts</h1>
|
|
23
|
-
<div class='clearfix'>
|
|
24
|
-
|
|
25
|
-
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">100% </span>
|
|
27
|
-
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>43/43</span>
|
|
29
|
-
</div>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">77.77% </span>
|
|
34
|
-
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>14/18</span>
|
|
36
|
-
</div>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">100% </span>
|
|
41
|
-
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>9/9</span>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">100% </span>
|
|
48
|
-
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>35/35</span>
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</div>
|
|
54
|
-
<p class="quiet">
|
|
55
|
-
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
-
</p>
|
|
57
|
-
<template id="filterTemplate">
|
|
58
|
-
<div class="quiet">
|
|
59
|
-
Filter:
|
|
60
|
-
<input type="search" id="fileSearch">
|
|
61
|
-
</div>
|
|
62
|
-
</template>
|
|
63
|
-
</div>
|
|
64
|
-
<div class='status-line high'></div>
|
|
65
|
-
<pre><table class="coverage">
|
|
66
|
-
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
-
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
-
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
-
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
-
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
-
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
-
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
-
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
-
<a name='L9'></a><a href='#L9'>9</a>
|
|
75
|
-
<a name='L10'></a><a href='#L10'>10</a>
|
|
76
|
-
<a name='L11'></a><a href='#L11'>11</a>
|
|
77
|
-
<a name='L12'></a><a href='#L12'>12</a>
|
|
78
|
-
<a name='L13'></a><a href='#L13'>13</a>
|
|
79
|
-
<a name='L14'></a><a href='#L14'>14</a>
|
|
80
|
-
<a name='L15'></a><a href='#L15'>15</a>
|
|
81
|
-
<a name='L16'></a><a href='#L16'>16</a>
|
|
82
|
-
<a name='L17'></a><a href='#L17'>17</a>
|
|
83
|
-
<a name='L18'></a><a href='#L18'>18</a>
|
|
84
|
-
<a name='L19'></a><a href='#L19'>19</a>
|
|
85
|
-
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
|
-
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
|
-
<a name='L22'></a><a href='#L22'>22</a>
|
|
88
|
-
<a name='L23'></a><a href='#L23'>23</a>
|
|
89
|
-
<a name='L24'></a><a href='#L24'>24</a>
|
|
90
|
-
<a name='L25'></a><a href='#L25'>25</a>
|
|
91
|
-
<a name='L26'></a><a href='#L26'>26</a>
|
|
92
|
-
<a name='L27'></a><a href='#L27'>27</a>
|
|
93
|
-
<a name='L28'></a><a href='#L28'>28</a>
|
|
94
|
-
<a name='L29'></a><a href='#L29'>29</a>
|
|
95
|
-
<a name='L30'></a><a href='#L30'>30</a>
|
|
96
|
-
<a name='L31'></a><a href='#L31'>31</a>
|
|
97
|
-
<a name='L32'></a><a href='#L32'>32</a>
|
|
98
|
-
<a name='L33'></a><a href='#L33'>33</a>
|
|
99
|
-
<a name='L34'></a><a href='#L34'>34</a>
|
|
100
|
-
<a name='L35'></a><a href='#L35'>35</a>
|
|
101
|
-
<a name='L36'></a><a href='#L36'>36</a>
|
|
102
|
-
<a name='L37'></a><a href='#L37'>37</a>
|
|
103
|
-
<a name='L38'></a><a href='#L38'>38</a>
|
|
104
|
-
<a name='L39'></a><a href='#L39'>39</a>
|
|
105
|
-
<a name='L40'></a><a href='#L40'>40</a>
|
|
106
|
-
<a name='L41'></a><a href='#L41'>41</a>
|
|
107
|
-
<a name='L42'></a><a href='#L42'>42</a>
|
|
108
|
-
<a name='L43'></a><a href='#L43'>43</a>
|
|
109
|
-
<a name='L44'></a><a href='#L44'>44</a>
|
|
110
|
-
<a name='L45'></a><a href='#L45'>45</a>
|
|
111
|
-
<a name='L46'></a><a href='#L46'>46</a>
|
|
112
|
-
<a name='L47'></a><a href='#L47'>47</a>
|
|
113
|
-
<a name='L48'></a><a href='#L48'>48</a>
|
|
114
|
-
<a name='L49'></a><a href='#L49'>49</a>
|
|
115
|
-
<a name='L50'></a><a href='#L50'>50</a>
|
|
116
|
-
<a name='L51'></a><a href='#L51'>51</a>
|
|
117
|
-
<a name='L52'></a><a href='#L52'>52</a>
|
|
118
|
-
<a name='L53'></a><a href='#L53'>53</a>
|
|
119
|
-
<a name='L54'></a><a href='#L54'>54</a>
|
|
120
|
-
<a name='L55'></a><a href='#L55'>55</a>
|
|
121
|
-
<a name='L56'></a><a href='#L56'>56</a>
|
|
122
|
-
<a name='L57'></a><a href='#L57'>57</a>
|
|
123
|
-
<a name='L58'></a><a href='#L58'>58</a>
|
|
124
|
-
<a name='L59'></a><a href='#L59'>59</a>
|
|
125
|
-
<a name='L60'></a><a href='#L60'>60</a>
|
|
126
|
-
<a name='L61'></a><a href='#L61'>61</a>
|
|
127
|
-
<a name='L62'></a><a href='#L62'>62</a>
|
|
128
|
-
<a name='L63'></a><a href='#L63'>63</a>
|
|
129
|
-
<a name='L64'></a><a href='#L64'>64</a>
|
|
130
|
-
<a name='L65'></a><a href='#L65'>65</a>
|
|
131
|
-
<a name='L66'></a><a href='#L66'>66</a>
|
|
132
|
-
<a name='L67'></a><a href='#L67'>67</a>
|
|
133
|
-
<a name='L68'></a><a href='#L68'>68</a>
|
|
134
|
-
<a name='L69'></a><a href='#L69'>69</a>
|
|
135
|
-
<a name='L70'></a><a href='#L70'>70</a>
|
|
136
|
-
<a name='L71'></a><a href='#L71'>71</a>
|
|
137
|
-
<a name='L72'></a><a href='#L72'>72</a>
|
|
138
|
-
<a name='L73'></a><a href='#L73'>73</a>
|
|
139
|
-
<a name='L74'></a><a href='#L74'>74</a>
|
|
140
|
-
<a name='L75'></a><a href='#L75'>75</a>
|
|
141
|
-
<a name='L76'></a><a href='#L76'>76</a>
|
|
142
|
-
<a name='L77'></a><a href='#L77'>77</a>
|
|
143
|
-
<a name='L78'></a><a href='#L78'>78</a>
|
|
144
|
-
<a name='L79'></a><a href='#L79'>79</a>
|
|
145
|
-
<a name='L80'></a><a href='#L80'>80</a>
|
|
146
|
-
<a name='L81'></a><a href='#L81'>81</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
|
147
|
-
<span class="cline-any cline-neutral"> </span>
|
|
148
|
-
<span class="cline-any cline-neutral"> </span>
|
|
149
|
-
<span class="cline-any cline-neutral"> </span>
|
|
150
|
-
<span class="cline-any cline-neutral"> </span>
|
|
151
|
-
<span class="cline-any cline-neutral"> </span>
|
|
152
|
-
<span class="cline-any cline-neutral"> </span>
|
|
153
|
-
<span class="cline-any cline-neutral"> </span>
|
|
154
|
-
<span class="cline-any cline-neutral"> </span>
|
|
155
|
-
<span class="cline-any cline-neutral"> </span>
|
|
156
|
-
<span class="cline-any cline-neutral"> </span>
|
|
157
|
-
<span class="cline-any cline-neutral"> </span>
|
|
158
|
-
<span class="cline-any cline-neutral"> </span>
|
|
159
|
-
<span class="cline-any cline-neutral"> </span>
|
|
160
|
-
<span class="cline-any cline-neutral"> </span>
|
|
161
|
-
<span class="cline-any cline-neutral"> </span>
|
|
162
|
-
<span class="cline-any cline-neutral"> </span>
|
|
163
|
-
<span class="cline-any cline-neutral"> </span>
|
|
164
|
-
<span class="cline-any cline-neutral"> </span>
|
|
165
|
-
<span class="cline-any cline-yes">11x</span>
|
|
166
|
-
<span class="cline-any cline-neutral"> </span>
|
|
167
|
-
<span class="cline-any cline-neutral"> </span>
|
|
168
|
-
<span class="cline-any cline-neutral"> </span>
|
|
169
|
-
<span class="cline-any cline-yes">4x</span>
|
|
170
|
-
<span class="cline-any cline-neutral"> </span>
|
|
171
|
-
<span class="cline-any cline-yes">4x</span>
|
|
172
|
-
<span class="cline-any cline-yes">1x</span>
|
|
173
|
-
<span class="cline-any cline-yes">1x</span>
|
|
174
|
-
<span class="cline-any cline-neutral"> </span>
|
|
175
|
-
<span class="cline-any cline-neutral"> </span>
|
|
176
|
-
<span class="cline-any cline-yes">3x</span>
|
|
177
|
-
<span class="cline-any cline-neutral"> </span>
|
|
178
|
-
<span class="cline-any cline-yes">3x</span>
|
|
179
|
-
<span class="cline-any cline-yes">3x</span>
|
|
180
|
-
<span class="cline-any cline-yes">3x</span>
|
|
181
|
-
<span class="cline-any cline-neutral"> </span>
|
|
182
|
-
<span class="cline-any cline-neutral"> </span>
|
|
183
|
-
<span class="cline-any cline-yes">3x</span>
|
|
184
|
-
<span class="cline-any cline-yes">1x</span>
|
|
185
|
-
<span class="cline-any cline-yes">1x</span>
|
|
186
|
-
<span class="cline-any cline-yes">1x</span>
|
|
187
|
-
<span class="cline-any cline-neutral"> </span>
|
|
188
|
-
<span class="cline-any cline-neutral"> </span>
|
|
189
|
-
<span class="cline-any cline-neutral"> </span>
|
|
190
|
-
<span class="cline-any cline-neutral"> </span>
|
|
191
|
-
<span class="cline-any cline-yes">3x</span>
|
|
192
|
-
<span class="cline-any cline-yes">3x</span>
|
|
193
|
-
<span class="cline-any cline-neutral"> </span>
|
|
194
|
-
<span class="cline-any cline-yes">3x</span>
|
|
195
|
-
<span class="cline-any cline-yes">3x</span>
|
|
196
|
-
<span class="cline-any cline-yes">3x</span>
|
|
197
|
-
<span class="cline-any cline-yes">2x</span>
|
|
198
|
-
<span class="cline-any cline-neutral"> </span>
|
|
199
|
-
<span class="cline-any cline-yes">2x</span>
|
|
200
|
-
<span class="cline-any cline-yes">2x</span>
|
|
201
|
-
<span class="cline-any cline-neutral"> </span>
|
|
202
|
-
<span class="cline-any cline-neutral"> </span>
|
|
203
|
-
<span class="cline-any cline-yes">1x</span>
|
|
204
|
-
<span class="cline-any cline-yes">1x</span>
|
|
205
|
-
<span class="cline-any cline-yes">1x</span>
|
|
206
|
-
<span class="cline-any cline-neutral"> </span>
|
|
207
|
-
<span class="cline-any cline-neutral"> </span>
|
|
208
|
-
<span class="cline-any cline-neutral"> </span>
|
|
209
|
-
<span class="cline-any cline-neutral"> </span>
|
|
210
|
-
<span class="cline-any cline-yes">3x</span>
|
|
211
|
-
<span class="cline-any cline-neutral"> </span>
|
|
212
|
-
<span class="cline-any cline-yes">3x</span>
|
|
213
|
-
<span class="cline-any cline-yes">3x</span>
|
|
214
|
-
<span class="cline-any cline-neutral"> </span>
|
|
215
|
-
<span class="cline-any cline-yes">3x</span>
|
|
216
|
-
<span class="cline-any cline-yes">1x</span>
|
|
217
|
-
<span class="cline-any cline-yes">1x</span>
|
|
218
|
-
<span class="cline-any cline-yes">1x</span>
|
|
219
|
-
<span class="cline-any cline-yes">2x</span>
|
|
220
|
-
<span class="cline-any cline-yes">1x</span>
|
|
221
|
-
<span class="cline-any cline-yes">1x</span>
|
|
222
|
-
<span class="cline-any cline-neutral"> </span>
|
|
223
|
-
<span class="cline-any cline-yes">1x</span>
|
|
224
|
-
<span class="cline-any cline-neutral"> </span>
|
|
225
|
-
<span class="cline-any cline-neutral"> </span>
|
|
226
|
-
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">// SPDX-License-Identifier: MIT
|
|
227
|
-
// Copyright (c) 2024–2026 Flavio De Musso
|
|
228
|
-
|
|
229
|
-
import pc from 'picocolors'
|
|
230
|
-
import type { Seed } from '@beechcms/core'
|
|
231
|
-
import { SEED_REGISTRY, validateSeedDefinitions } from '@beechcms/core'
|
|
232
|
-
|
|
233
|
-
export interface ValidateOptions {
|
|
234
|
-
registry?: Record<string, Seed> | null
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export interface SeedValidationError {
|
|
238
|
-
slug: string
|
|
239
|
-
messages: string[]
|
|
240
|
-
/** true = abort seed:load; false = warning only */
|
|
241
|
-
fatal: boolean
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function validateSeeds(registry: Record<string, Seed>): SeedValidationError[] {
|
|
245
|
-
return validateSeedDefinitions(Object.values(registry))
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export async function validate(args: ValidateOptions): Promise<void> {
|
|
249
|
-
const registry = args.registry ?? <span class="branch-1 cbranch-no" title="branch not covered" >SEED_REGISTRY</span>
|
|
250
|
-
|
|
251
|
-
if (Object.keys(registry).length === 0) {
|
|
252
|
-
console.warn(pc.yellow('\n Warning: SEED_REGISTRY is empty. Create a seeds.ts in your project root.\n'))
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
console.log(pc.cyan('\n beech validate — checking seeds\n'))
|
|
257
|
-
|
|
258
|
-
const errors = validateSeeds(registry)
|
|
259
|
-
const fatalErrors = errors.filter(e => e.fatal)
|
|
260
|
-
const warnings = errors.filter(e => !e.fatal)
|
|
261
|
-
|
|
262
|
-
// Print fatal errors first
|
|
263
|
-
for (const e of fatalErrors) {
|
|
264
|
-
console.log(pc.red(` ✗ ${e.slug} (fatal)`))
|
|
265
|
-
for (const msg of e.messages) {
|
|
266
|
-
console.log(pc.red(` → ${msg}`))
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Print per-seed warnings
|
|
271
|
-
const warningMap = new Map(warnings.map(e => [e.slug, e.messages]))
|
|
272
|
-
const allWarningSlugsSeen = new Set(warnings.map(e => e.slug))
|
|
273
|
-
|
|
274
|
-
for (const seed of Object.values(registry)) {
|
|
275
|
-
const msgs = warningMap.get(seed.slug)
|
|
276
|
-
if (!msgs) {
|
|
277
|
-
<span class="missing-if-branch" title="else path not taken" >E</span>if (!allWarningSlugsSeen.has(seed.slug)) {
|
|
278
|
-
// only print ✓ if no fatal error for this slug either
|
|
279
|
-
const hasFatal = fatalErrors.some(e => e.slug === seed.slug)
|
|
280
|
-
if (!hasFatal) console.log(pc.green(` ✓ ${seed.slug}`))
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
console.log(pc.yellow(` ⚠ ${seed.slug}`))
|
|
284
|
-
for (const msg of msgs) {
|
|
285
|
-
console.log(pc.yellow(` → ${msg}`))
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
console.log('')
|
|
291
|
-
|
|
292
|
-
const totalFatal = fatalErrors.reduce((n, e) => n + e.messages.length, 0)
|
|
293
|
-
const totalWarnings = warnings.reduce((n, e) => n + e.messages.length, 0)
|
|
294
|
-
|
|
295
|
-
if (totalFatal > 0) {
|
|
296
|
-
const s = totalFatal !== 1 ? <span class="branch-0 cbranch-no" title="branch not covered" >'s' : '</span>'
|
|
297
|
-
console.log(pc.red(` Found ${totalFatal} fatal error${s}. Fix before loading.\n`))
|
|
298
|
-
process.exit(1)
|
|
299
|
-
} else if (totalWarnings > 0) {
|
|
300
|
-
const s = totalWarnings !== 1 ? <span class="branch-0 cbranch-no" title="branch not covered" >'s' : '</span>'
|
|
301
|
-
console.log(pc.yellow(` Found ${totalWarnings} warning${s}. Review seeds above.\n`))
|
|
302
|
-
} else {
|
|
303
|
-
console.log(pc.green(' All seeds valid.\n'))
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
</pre></td></tr></table></pre>
|
|
307
|
-
|
|
308
|
-
<div class='push'></div><!-- for sticky footer -->
|
|
309
|
-
</div><!-- /wrapper -->
|
|
310
|
-
<div class='footer quiet pad2 space-top1 center small'>
|
|
311
|
-
Code coverage generated by
|
|
312
|
-
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
313
|
-
at 2026-06-12T11:07:37.845Z
|
|
314
|
-
</div>
|
|
315
|
-
<script src="prettify.js"></script>
|
|
316
|
-
<script>
|
|
317
|
-
window.onload = function () {
|
|
318
|
-
prettyPrint();
|
|
319
|
-
};
|
|
320
|
-
</script>
|
|
321
|
-
<script src="sorter.js"></script>
|
|
322
|
-
<script src="block-navigation.js"></script>
|
|
323
|
-
</body>
|
|
324
|
-
</html>
|
|
325
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"seed-load.d.ts","sourceRoot":"","sources":["../../src/commands/seed-load.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAiFD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAenE"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import pc from 'picocolors';
|
|
2
|
-
import { SEED_REGISTRY, generateCreateTable, generateIndexes, generateFtsTable, generateFtsTriggers, } from '@beech/core';
|
|
3
|
-
import { executeD1File, findWranglerConfig, resolveDbName } from '../lib/wrangler.js';
|
|
4
|
-
import { diffSeed } from '../lib/schema-diff.js';
|
|
5
|
-
function buildStatements(seed) {
|
|
6
|
-
const stmts = [generateCreateTable(seed), ...generateIndexes(seed)];
|
|
7
|
-
const fts = generateFtsTable(seed);
|
|
8
|
-
if (fts) {
|
|
9
|
-
stmts.push(fts, ...generateFtsTriggers(seed));
|
|
10
|
-
}
|
|
11
|
-
return stmts;
|
|
12
|
-
}
|
|
13
|
-
async function runDiff(options) {
|
|
14
|
-
const seeds = Object.values(SEED_REGISTRY);
|
|
15
|
-
console.log(pc.cyan('\n Diffing schema…\n'));
|
|
16
|
-
let allOk = true;
|
|
17
|
-
for (const seed of seeds) {
|
|
18
|
-
const result = await diffSeed(seed, options);
|
|
19
|
-
const tableName = `content_${seed.slug}`;
|
|
20
|
-
if (!result.tableExists) {
|
|
21
|
-
console.log(pc.red(` ✗ ${tableName} — table missing`));
|
|
22
|
-
allOk = false;
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
const problems = result.columns.filter(c => c.status !== 'ok');
|
|
26
|
-
if (problems.length === 0) {
|
|
27
|
-
console.log(pc.green(` ✓ ${tableName}`));
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
allOk = false;
|
|
31
|
-
console.log(pc.yellow(` ⚠ ${tableName}`));
|
|
32
|
-
for (const col of problems) {
|
|
33
|
-
if (col.status === 'missing') {
|
|
34
|
-
console.log(pc.red(` + missing column: ${col.name} ${col.expectedType}`));
|
|
35
|
-
}
|
|
36
|
-
else if (col.status === 'extra') {
|
|
37
|
-
console.log(pc.dim(` ~ extra column: ${col.name} ${col.actualType}`));
|
|
38
|
-
}
|
|
39
|
-
else if (col.status === 'type_mismatch') {
|
|
40
|
-
console.log(pc.red(` ≠ type mismatch: ${col.name} (expected ${col.expectedType}, got ${col.actualType})`));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
console.log('');
|
|
45
|
-
if (allOk) {
|
|
46
|
-
console.log(pc.green(' Schema matches seeds. No action needed.\n'));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
console.log(pc.yellow(' Run `beech seed:load` to apply missing tables/columns.\n'));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async function runLoad(options, dryRun) {
|
|
53
|
-
const seeds = Object.values(SEED_REGISTRY);
|
|
54
|
-
if (dryRun) {
|
|
55
|
-
console.log(pc.cyan('\n -- dry-run: SQL that would be executed\n'));
|
|
56
|
-
for (const seed of seeds) {
|
|
57
|
-
const stmts = buildStatements(seed);
|
|
58
|
-
console.log(pc.dim(` -- content_${seed.slug}`));
|
|
59
|
-
for (const stmt of stmts) {
|
|
60
|
-
console.log(stmt + '\n');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
console.log(pc.cyan(`\n Loading seeds into ${options.local ? 'local' : 'remote'} D1 (${options.db})…\n`));
|
|
66
|
-
for (const seed of seeds) {
|
|
67
|
-
const stmts = buildStatements(seed);
|
|
68
|
-
const sql = stmts.join('\n\n') + '\n';
|
|
69
|
-
process.stdout.write(` ${pc.dim('→')} content_${seed.slug}… `);
|
|
70
|
-
executeD1File(sql, options);
|
|
71
|
-
console.log(pc.green('done'));
|
|
72
|
-
}
|
|
73
|
-
console.log(pc.green('\n All seeds loaded.\n'));
|
|
74
|
-
}
|
|
75
|
-
export async function seedLoad(args) {
|
|
76
|
-
const configPath = findWranglerConfig();
|
|
77
|
-
const db = args.db ?? resolveDbName(configPath);
|
|
78
|
-
const options = {
|
|
79
|
-
db,
|
|
80
|
-
local: args.local,
|
|
81
|
-
configPath,
|
|
82
|
-
};
|
|
83
|
-
if (args.diff) {
|
|
84
|
-
await runDiff(options);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
await runLoad(options, args.dryRun);
|
|
88
|
-
}
|
|
89
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Seed } from '@beech/core';
|
|
2
|
-
import type { WranglerOptions } from './wrangler.js';
|
|
3
|
-
export interface ColumnDiff {
|
|
4
|
-
name: string;
|
|
5
|
-
status: 'ok' | 'missing' | 'extra' | 'type_mismatch';
|
|
6
|
-
expectedType?: string;
|
|
7
|
-
actualType?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface SeedDiff {
|
|
10
|
-
slug: string;
|
|
11
|
-
tableExists: boolean;
|
|
12
|
-
columns: ColumnDiff[];
|
|
13
|
-
}
|
|
14
|
-
export declare function diffSeed(seed: Seed, options: WranglerOptions): Promise<SeedDiff>;
|
|
15
|
-
//# sourceMappingURL=schema-diff.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-diff.d.ts","sourceRoot":"","sources":["../../src/lib/schema-diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAS,MAAM,eAAe,CAAA;AAU3D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,eAAe,CAAA;IACpD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,OAAO,CAAA;IACpB,OAAO,EAAE,UAAU,EAAE,CAAA;CACtB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsCtF"}
|
package/dist/lib/schema-diff.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { getExpectedColumns } from '@beech/core';
|
|
2
|
-
import { queryD1 } from './wrangler.js';
|
|
3
|
-
export async function diffSeed(seed, options) {
|
|
4
|
-
const tableName = `content_${seed.slug}`;
|
|
5
|
-
const expected = getExpectedColumns(seed);
|
|
6
|
-
let actual;
|
|
7
|
-
try {
|
|
8
|
-
actual = queryD1(`PRAGMA table_info(${tableName})`, options);
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return { slug: seed.slug, tableExists: false, columns: expected.map(c => ({ name: c.name, status: 'missing', expectedType: c.sqlType })) };
|
|
12
|
-
}
|
|
13
|
-
if (actual.length === 0) {
|
|
14
|
-
return { slug: seed.slug, tableExists: false, columns: expected.map(c => ({ name: c.name, status: 'missing', expectedType: c.sqlType })) };
|
|
15
|
-
}
|
|
16
|
-
const actualMap = new Map(actual.map(r => [r.name, r]));
|
|
17
|
-
const expectedSet = new Set(expected.map(c => c.name));
|
|
18
|
-
const columns = [];
|
|
19
|
-
for (const col of expected) {
|
|
20
|
-
const actual = actualMap.get(col.name);
|
|
21
|
-
if (!actual) {
|
|
22
|
-
columns.push({ name: col.name, status: 'missing', expectedType: col.sqlType });
|
|
23
|
-
}
|
|
24
|
-
else if (actual.type.toUpperCase() !== col.sqlType) {
|
|
25
|
-
columns.push({ name: col.name, status: 'type_mismatch', expectedType: col.sqlType, actualType: actual.type });
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
columns.push({ name: col.name, status: 'ok' });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
for (const row of actual) {
|
|
32
|
-
if (!expectedSet.has(row.name)) {
|
|
33
|
-
columns.push({ name: row.name, status: 'extra', actualType: row.type });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return { slug: seed.slug, tableExists: true, columns };
|
|
37
|
-
}
|
package/dist/lib/wrangler.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface WranglerOptions {
|
|
2
|
-
db: string;
|
|
3
|
-
local: boolean;
|
|
4
|
-
configPath: string | null;
|
|
5
|
-
}
|
|
6
|
-
export interface D1Row {
|
|
7
|
-
[key: string]: unknown;
|
|
8
|
-
}
|
|
9
|
-
/** Esegue SQL da file temporaneo via `wrangler d1 execute --file`. */
|
|
10
|
-
export declare function executeD1File(sql: string, options: WranglerOptions): void;
|
|
11
|
-
/** Esegue una query SQL e ritorna i risultati come array di oggetti (--json). */
|
|
12
|
-
export declare function queryD1<T extends D1Row = D1Row>(sql: string, options: WranglerOptions): T[];
|
|
13
|
-
/** Trova il path di wrangler.jsonc in apps/api/ relativo a cwd. */
|
|
14
|
-
export declare function findWranglerConfig(): string | null;
|
|
15
|
-
/** Risolve il nome del database D1 da wrangler.jsonc (grepping 'database_name'). */
|
|
16
|
-
export declare function resolveDbName(configPath: string | null): string;
|
|
17
|
-
//# sourceMappingURL=wrangler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/lib/wrangler.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,MAAM,WAAW,KAAK;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAgBD,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI,CAYzE;AAED,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,CAAC,EAAE,CAc3F;AAED,mEAAmE;AACnE,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAGlD;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAS/D"}
|
package/dist/lib/wrangler.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { execSync, spawnSync } from 'node:child_process';
|
|
2
|
-
import { writeFileSync, rmSync, existsSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join, resolve } from 'node:path';
|
|
5
|
-
function buildArgs(options) {
|
|
6
|
-
const args = [];
|
|
7
|
-
if (options.configPath)
|
|
8
|
-
args.push('--config', options.configPath);
|
|
9
|
-
if (options.local)
|
|
10
|
-
args.push('--local');
|
|
11
|
-
else
|
|
12
|
-
args.push('--remote');
|
|
13
|
-
return args;
|
|
14
|
-
}
|
|
15
|
-
/** Esegue SQL da file temporaneo via `wrangler d1 execute --file`. */
|
|
16
|
-
export function executeD1File(sql, options) {
|
|
17
|
-
const tmpFile = join(tmpdir(), `beech-seed-${Date.now()}.sql`);
|
|
18
|
-
try {
|
|
19
|
-
writeFileSync(tmpFile, sql, 'utf-8');
|
|
20
|
-
const args = ['d1', 'execute', options.db, '--file', tmpFile, ...buildArgs(options)];
|
|
21
|
-
const result = spawnSync('npx', ['wrangler', ...args], { stdio: 'inherit', cwd: process.cwd() });
|
|
22
|
-
if (result.status !== 0) {
|
|
23
|
-
process.exit(result.status ?? 1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
try {
|
|
28
|
-
rmSync(tmpFile);
|
|
29
|
-
}
|
|
30
|
-
catch { }
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/** Esegue una query SQL e ritorna i risultati come array di oggetti (--json). */
|
|
34
|
-
export function queryD1(sql, options) {
|
|
35
|
-
const args = ['d1', 'execute', options.db, '--command', sql, '--json', ...buildArgs(options)];
|
|
36
|
-
const result = spawnSync('npx', ['wrangler', ...args], { encoding: 'utf-8', cwd: process.cwd() });
|
|
37
|
-
if (result.status !== 0) {
|
|
38
|
-
throw new Error(`wrangler d1 execute failed:\n${result.stderr}`);
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const parsed = JSON.parse(result.stdout);
|
|
42
|
-
return (parsed[0]?.results ?? []);
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
throw new Error(`Failed to parse wrangler JSON output:\n${result.stdout}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/** Trova il path di wrangler.jsonc in apps/api/ relativo a cwd. */
|
|
49
|
-
export function findWranglerConfig() {
|
|
50
|
-
const candidate = resolve(process.cwd(), 'apps', 'api', 'wrangler.jsonc');
|
|
51
|
-
return existsSync(candidate) ? candidate : null;
|
|
52
|
-
}
|
|
53
|
-
/** Risolve il nome del database D1 da wrangler.jsonc (grepping 'database_name'). */
|
|
54
|
-
export function resolveDbName(configPath) {
|
|
55
|
-
if (!configPath)
|
|
56
|
-
return 'beech-db';
|
|
57
|
-
try {
|
|
58
|
-
const content = execSync(`cat "${configPath}"`, { encoding: 'utf-8' });
|
|
59
|
-
const match = content.match(/"database_name"\s*:\s*"([^"]+)"/);
|
|
60
|
-
return match?.[1] ?? 'beech-db';
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
return 'beech-db';
|
|
64
|
-
}
|
|
65
|
-
}
|