@caretcms/core 0.1.0 → 0.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.
Files changed (191) hide show
  1. package/README.md +117 -6
  2. package/dist/browser-runtime.d.ts.map +1 -1
  3. package/dist/browser-runtime.js +34 -20
  4. package/dist/browser-runtime.js.map +1 -1
  5. package/dist/contracts.d.ts +14 -0
  6. package/dist/contracts.d.ts.map +1 -0
  7. package/dist/contracts.js +14 -0
  8. package/dist/contracts.js.map +1 -0
  9. package/dist/editable.d.ts +28 -0
  10. package/dist/editable.d.ts.map +1 -0
  11. package/dist/editable.js +122 -0
  12. package/dist/editable.js.map +1 -0
  13. package/dist/index.d.ts +30 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +134 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/loader.d.ts.map +1 -1
  18. package/dist/loader.js +45 -3
  19. package/dist/loader.js.map +1 -1
  20. package/dist/providers/storage/markdown.d.ts +7 -0
  21. package/dist/providers/storage/markdown.d.ts.map +1 -0
  22. package/dist/providers/storage/markdown.js +6 -0
  23. package/dist/providers/storage/markdown.js.map +1 -0
  24. package/dist/runtime/auth/cookie-utils.d.ts +1 -0
  25. package/dist/runtime/auth/cookie-utils.d.ts.map +1 -1
  26. package/dist/runtime/auth/cookie-utils.js +1 -1
  27. package/dist/runtime/auth/cookie-utils.js.map +1 -1
  28. package/dist/runtime/auth/rate-limiter.d.ts.map +1 -1
  29. package/dist/runtime/auth/rate-limiter.js +19 -13
  30. package/dist/runtime/auth/rate-limiter.js.map +1 -1
  31. package/dist/runtime/auth/session.d.ts +8 -0
  32. package/dist/runtime/auth/session.d.ts.map +1 -1
  33. package/dist/runtime/auth/session.js +72 -11
  34. package/dist/runtime/auth/session.js.map +1 -1
  35. package/dist/runtime/config.d.ts +1 -0
  36. package/dist/runtime/config.d.ts.map +1 -1
  37. package/dist/runtime/config.js +2 -1
  38. package/dist/runtime/config.js.map +1 -1
  39. package/dist/runtime/git-journal.d.ts +19 -0
  40. package/dist/runtime/git-journal.d.ts.map +1 -0
  41. package/dist/runtime/git-journal.js +64 -0
  42. package/dist/runtime/git-journal.js.map +1 -0
  43. package/dist/runtime/index.d.ts +1 -1
  44. package/dist/runtime/index.d.ts.map +1 -1
  45. package/dist/runtime/index.js +1 -1
  46. package/dist/runtime/index.js.map +1 -1
  47. package/dist/runtime/middleware.d.ts.map +1 -1
  48. package/dist/runtime/middleware.js +125 -8
  49. package/dist/runtime/middleware.js.map +1 -1
  50. package/dist/runtime/mutations/contracts.d.ts.map +1 -1
  51. package/dist/runtime/mutations/contracts.js +7 -4
  52. package/dist/runtime/mutations/contracts.js.map +1 -1
  53. package/dist/runtime/mutations/engine.d.ts +7 -0
  54. package/dist/runtime/mutations/engine.d.ts.map +1 -1
  55. package/dist/runtime/mutations/engine.js +30 -17
  56. package/dist/runtime/mutations/engine.js.map +1 -1
  57. package/dist/runtime/providers.d.ts +7 -0
  58. package/dist/runtime/providers.d.ts.map +1 -1
  59. package/dist/runtime/providers.js +10 -0
  60. package/dist/runtime/providers.js.map +1 -1
  61. package/dist/runtime/publish.d.ts +38 -0
  62. package/dist/runtime/publish.d.ts.map +1 -0
  63. package/dist/runtime/publish.js +71 -0
  64. package/dist/runtime/publish.js.map +1 -0
  65. package/dist/runtime/request-context.d.ts +19 -0
  66. package/dist/runtime/request-context.d.ts.map +1 -1
  67. package/dist/runtime/request-context.js.map +1 -1
  68. package/dist/runtime/rewrite.d.ts +11 -1
  69. package/dist/runtime/rewrite.d.ts.map +1 -1
  70. package/dist/runtime/rewrite.js +21 -15
  71. package/dist/runtime/rewrite.js.map +1 -1
  72. package/dist/runtime/rich-allowlist.d.ts +28 -0
  73. package/dist/runtime/rich-allowlist.d.ts.map +1 -0
  74. package/dist/runtime/rich-allowlist.js +43 -0
  75. package/dist/runtime/rich-allowlist.js.map +1 -0
  76. package/dist/runtime/routes/_helpers.d.ts +26 -0
  77. package/dist/runtime/routes/_helpers.d.ts.map +1 -1
  78. package/dist/runtime/routes/_helpers.js +83 -0
  79. package/dist/runtime/routes/_helpers.js.map +1 -1
  80. package/dist/runtime/routes/admin.d.ts.map +1 -1
  81. package/dist/runtime/routes/admin.js +55 -6
  82. package/dist/runtime/routes/admin.js.map +1 -1
  83. package/dist/runtime/routes/auth-login.d.ts.map +1 -1
  84. package/dist/runtime/routes/auth-login.js +25 -8
  85. package/dist/runtime/routes/auth-login.js.map +1 -1
  86. package/dist/runtime/routes/auth-logout.d.ts.map +1 -1
  87. package/dist/runtime/routes/auth-logout.js +4 -0
  88. package/dist/runtime/routes/auth-logout.js.map +1 -1
  89. package/dist/runtime/routes/collections-metadata.d.ts.map +1 -1
  90. package/dist/runtime/routes/collections-metadata.js +4 -2
  91. package/dist/runtime/routes/collections-metadata.js.map +1 -1
  92. package/dist/runtime/routes/draft.d.ts +8 -0
  93. package/dist/runtime/routes/draft.d.ts.map +1 -0
  94. package/dist/runtime/routes/draft.js +38 -0
  95. package/dist/runtime/routes/draft.js.map +1 -0
  96. package/dist/runtime/routes/history.d.ts.map +1 -1
  97. package/dist/runtime/routes/history.js +21 -8
  98. package/dist/runtime/routes/history.js.map +1 -1
  99. package/dist/runtime/routes/mutate.d.ts.map +1 -1
  100. package/dist/runtime/routes/mutate.js +5 -9
  101. package/dist/runtime/routes/mutate.js.map +1 -1
  102. package/dist/runtime/routes/publish.d.ts +9 -0
  103. package/dist/runtime/routes/publish.d.ts.map +1 -0
  104. package/dist/runtime/routes/publish.js +66 -0
  105. package/dist/runtime/routes/publish.js.map +1 -0
  106. package/dist/runtime/routes/schema.d.ts.map +1 -1
  107. package/dist/runtime/routes/schema.js +4 -2
  108. package/dist/runtime/routes/schema.js.map +1 -1
  109. package/dist/runtime/routes/upload.d.ts.map +1 -1
  110. package/dist/runtime/routes/upload.js +16 -3
  111. package/dist/runtime/routes/upload.js.map +1 -1
  112. package/dist/runtime/sanitize-html.d.ts +8 -2
  113. package/dist/runtime/sanitize-html.d.ts.map +1 -1
  114. package/dist/runtime/sanitize-html.js +57 -38
  115. package/dist/runtime/sanitize-html.js.map +1 -1
  116. package/dist/runtime/stega.d.ts +38 -0
  117. package/dist/runtime/stega.d.ts.map +1 -0
  118. package/dist/runtime/stega.js +98 -0
  119. package/dist/runtime/stega.js.map +1 -0
  120. package/dist/runtime/storage/atomic-write.d.ts +22 -0
  121. package/dist/runtime/storage/atomic-write.d.ts.map +1 -0
  122. package/dist/runtime/storage/atomic-write.js +44 -0
  123. package/dist/runtime/storage/atomic-write.js.map +1 -0
  124. package/dist/runtime/storage/filesystem-adapter.d.ts +14 -11
  125. package/dist/runtime/storage/filesystem-adapter.d.ts.map +1 -1
  126. package/dist/runtime/storage/filesystem-adapter.js +71 -201
  127. package/dist/runtime/storage/filesystem-adapter.js.map +1 -1
  128. package/dist/runtime/storage/frontmatter-codec.d.ts +47 -0
  129. package/dist/runtime/storage/frontmatter-codec.d.ts.map +1 -0
  130. package/dist/runtime/storage/frontmatter-codec.js +515 -0
  131. package/dist/runtime/storage/frontmatter-codec.js.map +1 -0
  132. package/dist/runtime/storage/fs-runtime.d.ts +8 -0
  133. package/dist/runtime/storage/fs-runtime.d.ts.map +1 -0
  134. package/dist/runtime/storage/fs-runtime.js +40 -0
  135. package/dist/runtime/storage/fs-runtime.js.map +1 -0
  136. package/dist/runtime/storage/id-contracts.d.ts +22 -0
  137. package/dist/runtime/storage/id-contracts.d.ts.map +1 -0
  138. package/dist/runtime/storage/id-contracts.js +27 -0
  139. package/dist/runtime/storage/id-contracts.js.map +1 -0
  140. package/dist/runtime/storage/image-validation.d.ts +10 -0
  141. package/dist/runtime/storage/image-validation.d.ts.map +1 -1
  142. package/dist/runtime/storage/image-validation.js +17 -4
  143. package/dist/runtime/storage/image-validation.js.map +1 -1
  144. package/dist/runtime/storage/in-memory-adapter.d.ts +4 -0
  145. package/dist/runtime/storage/in-memory-adapter.d.ts.map +1 -1
  146. package/dist/runtime/storage/in-memory-adapter.js +11 -0
  147. package/dist/runtime/storage/in-memory-adapter.js.map +1 -1
  148. package/dist/runtime/storage/markdown-adapter.d.ts +63 -0
  149. package/dist/runtime/storage/markdown-adapter.d.ts.map +1 -0
  150. package/dist/runtime/storage/markdown-adapter.js +227 -0
  151. package/dist/runtime/storage/markdown-adapter.js.map +1 -0
  152. package/dist/runtime/storage/quota-upload-handler.d.ts +2 -0
  153. package/dist/runtime/storage/quota-upload-handler.d.ts.map +1 -1
  154. package/dist/runtime/storage/quota-upload-handler.js +34 -8
  155. package/dist/runtime/storage/quota-upload-handler.js.map +1 -1
  156. package/dist/runtime/storage/session-overlay-adapter.d.ts +3 -0
  157. package/dist/runtime/storage/session-overlay-adapter.d.ts.map +1 -1
  158. package/dist/runtime/storage/session-overlay-adapter.js +3 -1
  159. package/dist/runtime/storage/session-overlay-adapter.js.map +1 -1
  160. package/dist/runtime/storage/sidecar-meta-store.d.ts +51 -0
  161. package/dist/runtime/storage/sidecar-meta-store.d.ts.map +1 -0
  162. package/dist/runtime/storage/sidecar-meta-store.js +209 -0
  163. package/dist/runtime/storage/sidecar-meta-store.js.map +1 -0
  164. package/dist/runtime/themes/preset-tokens.d.ts +0 -1
  165. package/dist/runtime/themes/preset-tokens.d.ts.map +1 -1
  166. package/dist/runtime/themes/preset-tokens.js +1 -1
  167. package/dist/runtime/themes/preset-tokens.js.map +1 -1
  168. package/dist/runtime/utils.d.ts +9 -1
  169. package/dist/runtime/utils.d.ts.map +1 -1
  170. package/dist/runtime/utils.js +21 -1
  171. package/dist/runtime/utils.js.map +1 -1
  172. package/dist/schema-utils.d.ts.map +1 -1
  173. package/dist/schema-utils.js +1 -0
  174. package/dist/schema-utils.js.map +1 -1
  175. package/dist/types.d.ts +17 -0
  176. package/dist/types.d.ts.map +1 -1
  177. package/package.json +9 -1
  178. package/static/cms/dev-toolbar/app.js +263 -0
  179. package/static/cms/editor/highlight.js +46 -0
  180. package/static/cms/editor/sanitize.js +48 -5
  181. package/static/cms/editor/stega-hydrate.js +80 -0
  182. package/static/cms/editor/text-edit.js +22 -0
  183. package/static/cms/editor/tokens-and-text.css +1 -1
  184. package/static/cms/editor/toolbar.css +42 -0
  185. package/static/cms/editor/toolbar.js +97 -15
  186. package/static/cms/editor.js +15 -0
  187. package/static/cms/signin-hint.css +74 -0
  188. package/dist/runtime/schema/template.d.ts +0 -15
  189. package/dist/runtime/schema/template.d.ts.map +0 -1
  190. package/dist/runtime/schema/template.js +0 -38
  191. package/dist/runtime/schema/template.js.map +0 -1
@@ -1,3 +1,18 @@
1
+ import { toggleHighlight } from './highlight.js';
2
+ import { buildCmsUrl } from './config.js';
3
+
4
+ const PREVIEW_COOKIE = 'caret_preview';
5
+
6
+ function previewActive() {
7
+ return document.cookie.split('; ').some((c) => c === `${PREVIEW_COOKIE}=1`);
8
+ }
9
+
10
+ function setPreviewCookie(on) {
11
+ document.cookie = on
12
+ ? `${PREVIEW_COOKIE}=1; path=/; SameSite=Lax`
13
+ : `${PREVIEW_COOKIE}=; path=/; Max-Age=0; SameSite=Lax`;
14
+ }
15
+
1
16
  function getToolbarNavLinks(pagePath) {
2
17
  const links = [];
3
18
  const headerNav = document.querySelector('#main-header nav');
@@ -39,6 +54,19 @@ function renderToolbar(navLinks) {
39
54
  </div>
40
55
  ${navLinksHtml ? `<div class="cms-toolbar-nav">${navLinksHtml}</div>` : ''}
41
56
  <div class="cms-toolbar-right">
57
+ <button class="cms-preview-btn" type="button" title="Toggle draft preview — edit without publishing to the live site">
58
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
59
+ Preview
60
+ </button>
61
+ <button class="cms-publish-btn" type="button" title="Publish your draft changes to the live site" hidden>
62
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5"/><polyline points="5 12 12 5 19 12"/></svg>
63
+ Publish
64
+ </button>
65
+ <button class="cms-discard-btn" type="button" title="Discard your draft changes" hidden>
66
+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
67
+ Discard
68
+ </button>
69
+ <div class="cms-toolbar-divider"></div>
42
70
  <button type="button" class="cms-studio-btn" title="Toggle Content Studio panel">
43
71
  <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="3" x2="9" y2="21"/><line x1="9" y1="9" x2="21" y2="9"/></svg>
44
72
  Studio
@@ -81,29 +109,83 @@ export function mountToolbar({ showToast, clearDirty, onLogout }) {
81
109
  }
82
110
  }
83
111
 
84
- let highlightActive = false;
85
112
  const highlightBtn = toolbar.querySelector('.cms-highlight-btn');
113
+ highlightBtn?.addEventListener('click', () =>
114
+ toggleHighlight(highlightBtn, showToast),
115
+ );
116
+
117
+ toolbar.querySelector('.cms-exit-btn')?.addEventListener('click', async () => {
118
+ clearDirty();
119
+ await onLogout();
120
+ });
86
121
 
87
- highlightBtn?.addEventListener('click', () => {
88
- highlightActive = !highlightActive;
89
- document.body.classList.toggle('cms-highlight-all', highlightActive);
90
- highlightBtn.classList.toggle('cms-highlight-btn-active', highlightActive);
122
+ // --- Draft preview + publish/discard ---
123
+ const previewBtn = toolbar.querySelector('.cms-preview-btn');
124
+ const publishBtn = toolbar.querySelector('.cms-publish-btn');
125
+ const discardBtn = toolbar.querySelector('.cms-discard-btn');
126
+ const badgeText = toolbar.querySelector('.cms-toolbar-badge-text');
91
127
 
92
- const textNode = Array.from(highlightBtn.childNodes).find(
93
- (n) => n.nodeType === 3 && n.textContent?.trim(),
128
+ function reflectPreview() {
129
+ const on = previewActive();
130
+ previewBtn?.classList.toggle('cms-preview-btn-active', on);
131
+ if (publishBtn) publishBtn.hidden = !on;
132
+ if (discardBtn) discardBtn.hidden = !on;
133
+ if (badgeText) badgeText.textContent = on ? 'Draft' : 'Editor';
134
+ const label = previewBtn
135
+ && Array.from(previewBtn.childNodes).find((n) => n.nodeType === 3 && n.textContent?.trim());
136
+ if (label) label.textContent = on ? ' Previewing' : ' Preview';
137
+ }
138
+ reflectPreview();
139
+
140
+ previewBtn?.addEventListener('click', () => {
141
+ const turningOn = !previewActive();
142
+ setPreviewCookie(turningOn);
143
+ showToast(
144
+ turningOn ? 'Draft preview on — your edits stay unpublished' : 'Draft preview off',
145
+ 'success',
94
146
  );
147
+ // Reload so the server installs (or drops) the per-editor draft overlay.
148
+ window.location.reload();
149
+ });
95
150
 
96
- if (highlightActive) {
97
- if (textNode) textNode.textContent = ' Hide All';
98
- showToast('Showing all editable regions', 'success');
99
- } else {
100
- if (textNode) textNode.textContent = ' Show All';
151
+ async function draftRequest(method, path) {
152
+ return fetch(buildCmsUrl(path), {
153
+ method,
154
+ headers: { 'Content-Type': 'application/json', 'x-caret-request': '1' },
155
+ credentials: 'same-origin',
156
+ body: method === 'POST' ? '{}' : undefined,
157
+ });
158
+ }
159
+
160
+ publishBtn?.addEventListener('click', async () => {
161
+ if (!window.confirm('Publish all your draft changes to the live site?')) return;
162
+ setStatus('saving', 'Publishing…');
163
+ try {
164
+ const res = await draftRequest('POST', '/publish');
165
+ if (!res.ok) throw new Error('publish failed');
166
+ const data = await res.json();
167
+ const n = Array.isArray(data.published) ? data.published.length : 0;
168
+ // Drafts are flushed; leave preview so the editor sees the published site.
169
+ setPreviewCookie(false);
170
+ showToast(`Published ${n} change(s)`, 'success');
171
+ window.location.reload();
172
+ } catch {
173
+ setStatus('error', 'Publish failed');
174
+ showToast('Publish failed', 'error');
101
175
  }
102
176
  });
103
177
 
104
- toolbar.querySelector('.cms-exit-btn')?.addEventListener('click', async () => {
105
- clearDirty();
106
- await onLogout();
178
+ discardBtn?.addEventListener('click', async () => {
179
+ if (!window.confirm('Discard all your draft changes? This cannot be undone.')) return;
180
+ try {
181
+ const res = await draftRequest('DELETE', '/draft');
182
+ if (!res.ok) throw new Error('discard failed');
183
+ setPreviewCookie(false);
184
+ showToast('Draft discarded', 'success');
185
+ window.location.reload();
186
+ } catch {
187
+ showToast('Discard failed', 'error');
188
+ }
107
189
  });
108
190
 
109
191
  const studioButton = toolbar.querySelector('.cms-studio-btn');
@@ -25,6 +25,8 @@ import { mountSectionControls } from './editor/section-controls.js';
25
25
  import { mountContentMap } from './editor/content-map.js';
26
26
  import { mountRichToolbar } from './editor/rich-toolbar.js';
27
27
  import { mountLinkFollowAffordances } from './editor/link-follow.js';
28
+ import { revealAndFade } from './editor/highlight.js';
29
+ import { hydrateStega } from './editor/stega-hydrate.js';
28
30
 
29
31
  function redirectToEditorLogin() {
30
32
  window.location.href = getEditorLoginUrl(window.location.href);
@@ -36,6 +38,10 @@ function boot() {
36
38
  linkPopupEl: null,
37
39
  };
38
40
 
41
+ // Promote stega-tagged (loader-fed) content into data-caret bindings before
42
+ // any scanner runs, so prop/component/loop content is click-to-edit too.
43
+ hydrateStega();
44
+
39
45
  mountEditorGuards(state);
40
46
  mountLinkFollowAffordances();
41
47
 
@@ -107,6 +113,15 @@ function boot() {
107
113
  });
108
114
 
109
115
  mountInlineEditors();
116
+
117
+ // First load after login: flash every editable region once, then fade out.
118
+ // The flag is set by the login form just before it redirects here.
119
+ try {
120
+ if (sessionStorage.getItem('caret:welcome')) {
121
+ sessionStorage.removeItem('caret:welcome');
122
+ revealAndFade(2500);
123
+ }
124
+ } catch (e) {}
110
125
  }
111
126
 
112
127
  if (document.readyState === 'loading') {
@@ -0,0 +1,74 @@
1
+ /*
2
+ * The authenticated empty-state hint: shown by the middleware on a live page
3
+ * when an editor is signed in but the page has zero `data-caret` bindings — the
4
+ * silent dead-end this replaces (you land on a normal page with no sign the
5
+ * editor noticed you). Self-contained and isolated (`all: initial` on the host)
6
+ * so it can't be restyled by — or restyle — the host page, and so it needs no
7
+ * inline styles (CSP `style-src 'self'` covers this same-origin file).
8
+ */
9
+ .caret-signin-hint {
10
+ all: initial;
11
+ position: fixed;
12
+ bottom: 16px;
13
+ left: 16px;
14
+ z-index: 2147483000;
15
+ box-sizing: border-box;
16
+ display: flex;
17
+ align-items: center;
18
+ gap: 10px;
19
+ max-width: min(92vw, 400px);
20
+ padding: 10px 14px;
21
+ font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
22
+ font-size: 13px;
23
+ line-height: 1.45;
24
+ color: #e5e7eb;
25
+ background: #111827;
26
+ border: 1px solid #374151;
27
+ border-radius: 10px;
28
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
29
+ }
30
+
31
+ .caret-signin-hint__dot {
32
+ flex: 0 0 auto;
33
+ width: 8px;
34
+ height: 8px;
35
+ border-radius: 50%;
36
+ background: #34d399;
37
+ box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
38
+ }
39
+
40
+ .caret-signin-hint__text {
41
+ color: inherit;
42
+ font: inherit;
43
+ }
44
+
45
+ .caret-signin-hint code {
46
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
47
+ font-size: 0.92em;
48
+ color: #f9fafb;
49
+ background: #1f2937;
50
+ padding: 1px 5px;
51
+ border-radius: 5px;
52
+ }
53
+
54
+ .caret-signin-hint a {
55
+ color: #93c5fd;
56
+ font: inherit;
57
+ text-decoration: underline;
58
+ white-space: nowrap;
59
+ }
60
+
61
+ @media (prefers-color-scheme: light) {
62
+ .caret-signin-hint {
63
+ color: #1f2937;
64
+ background: #ffffff;
65
+ border-color: #e5e7eb;
66
+ }
67
+ .caret-signin-hint code {
68
+ color: #111827;
69
+ background: #f3f4f6;
70
+ }
71
+ .caret-signin-hint a {
72
+ color: #2563eb;
73
+ }
74
+ }
@@ -1,15 +0,0 @@
1
- /**
2
- * Build a default entry template from a JSON Schema.
3
- *
4
- * Used to seed initial data for new entries in dynamically-created
5
- * collections. Pure JSON-Schema → value mapping; no validation library
6
- * (schemas reach core as JSON Schema, e.g. via the caller's own
7
- * `z.toJSONSchema()`), so core stays Zod-agnostic.
8
- */
9
- import type { CollectionSchema } from "../../types.js";
10
- /**
11
- * Generate a default template from a JSON Schema.
12
- * Used to create initial data for new entries in dynamic collections.
13
- */
14
- export declare function generateTemplateFromSchema(jsonSchema: CollectionSchema): Record<string, unknown>;
15
- //# sourceMappingURL=template.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/runtime/schema/template.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAOvD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBhG"}
@@ -1,38 +0,0 @@
1
- /**
2
- * Build a default entry template from a JSON Schema.
3
- *
4
- * Used to seed initial data for new entries in dynamically-created
5
- * collections. Pure JSON-Schema → value mapping; no validation library
6
- * (schemas reach core as JSON Schema, e.g. via the caller's own
7
- * `z.toJSONSchema()`), so core stays Zod-agnostic.
8
- */
9
- /**
10
- * Generate a default template from a JSON Schema.
11
- * Used to create initial data for new entries in dynamic collections.
12
- */
13
- export function generateTemplateFromSchema(jsonSchema) {
14
- const template = {};
15
- for (const [key, prop] of Object.entries(jsonSchema.properties)) {
16
- const p = prop;
17
- if (p.default !== undefined) {
18
- template[key] = p.default;
19
- }
20
- else if (p.type === "string") {
21
- template[key] = "";
22
- }
23
- else if (p.type === "number" || p.type === "integer") {
24
- template[key] = 0;
25
- }
26
- else if (p.type === "boolean") {
27
- template[key] = false;
28
- }
29
- else if (p.type === "array") {
30
- template[key] = [];
31
- }
32
- else if (p.type === "object") {
33
- template[key] = {};
34
- }
35
- }
36
- return template;
37
- }
38
- //# sourceMappingURL=template.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/runtime/schema/template.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAA4B;IACrE,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAChE,MAAM,CAAC,GAAG,IAA0B,CAAC;QAErC,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAC5B,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;QAC5B,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC/B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACrB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACvD,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAChC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC9B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACrB,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC/B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}