includio-cms 0.6.0 → 0.6.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/CHANGELOG.md +19 -0
- package/ROADMAP.md +20 -4
- package/dist/admin/client/collection/collection-entries.svelte +43 -1
- package/dist/admin/client/collection/table-toolbar.svelte +64 -1
- package/dist/admin/client/collection/table-toolbar.svelte.d.ts +11 -0
- package/dist/admin/components/fields/field-renderer.svelte +3 -2
- package/dist/admin/components/fields/field-renderer.svelte.d.ts +1 -0
- package/dist/admin/components/fields/object-field.svelte +5 -5
- package/dist/admin/components/fields/object-field.svelte.d.ts +1 -1
- package/dist/admin/components/fields/text-field-wrapper.svelte +5 -3
- package/dist/admin/components/layout/layout-renderer.svelte +81 -107
- package/dist/admin/components/layout/layout-renderer.svelte.d.ts +1 -0
- package/dist/admin/components/tiptap/InlineBlockNodeView.svelte +13 -6
- package/dist/admin/components/tiptap/content-editor.svelte +11 -2
- package/dist/admin/styles/admin.css +2 -1
- package/dist/ai-claude/index.js +10 -4
- package/dist/cli/index.js +10 -3
- package/dist/cli/install-peers.d.ts +3 -0
- package/dist/cli/install-peers.js +52 -0
- package/dist/core/fields/fieldSchemaToTs.js +2 -0
- package/dist/core/fields/layoutUtils.d.ts +30 -3
- package/dist/core/fields/layoutUtils.js +145 -17
- package/dist/core/server/generator/generator.js +21 -10
- package/dist/entity/index.d.ts +26 -0
- package/dist/entity/index.js +113 -0
- package/dist/paraglide/messages/_index.d.ts +36 -3
- package/dist/paraglide/messages/_index.js +71 -3
- package/dist/paraglide/messages/en.d.ts +5 -0
- package/dist/paraglide/messages/en.js +14 -0
- package/dist/paraglide/messages/pl.d.ts +5 -0
- package/dist/paraglide/messages/pl.js +14 -0
- package/dist/types/layout.d.ts +8 -0
- package/dist/updates/0.6.0/index.d.ts +2 -0
- package/dist/updates/0.6.0/index.js +20 -0
- package/dist/updates/index.js +2 -1
- package/package.json +20 -6
- package/dist/paraglide/messages/hello_world.d.ts +0 -5
- package/dist/paraglide/messages/hello_world.js +0 -33
- package/dist/paraglide/messages/login_hello.d.ts +0 -16
- package/dist/paraglide/messages/login_hello.js +0 -34
- package/dist/paraglide/messages/login_please_login.d.ts +0 -16
- package/dist/paraglide/messages/login_please_login.js +0 -34
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
import Trash from '@tabler/icons-svelte/icons/trash';
|
|
12
12
|
import ChevronDown from '@tabler/icons-svelte/icons/chevron-down';
|
|
13
13
|
import { slide } from 'svelte/transition';
|
|
14
|
-
import { onMount, onDestroy } from 'svelte';
|
|
14
|
+
import { onMount, onDestroy, setContext } from 'svelte';
|
|
15
15
|
import type { FormPathLeaves } from 'sveltekit-superforms';
|
|
16
16
|
import { evaluateCondition } from '../../utils/fieldCondition.js';
|
|
17
17
|
import { isRecentlyInserted } from './inline-block-node.js';
|
|
18
18
|
|
|
19
19
|
let { node, updateAttributes, editor, getPos, deleteNode }: NodeViewProps = $props();
|
|
20
20
|
|
|
21
|
+
setContext('inInlineBlock', true);
|
|
22
|
+
|
|
21
23
|
let collapsed = $state(!isRecentlyInserted(node.attrs.blockId));
|
|
22
24
|
|
|
23
25
|
const contentLanguage = getContentLanguage();
|
|
@@ -33,9 +35,14 @@
|
|
|
33
35
|
for (const f of fields) {
|
|
34
36
|
const key = f.slug;
|
|
35
37
|
if (['text', 'richtext', 'content'].includes(f.type)) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const val = result[key];
|
|
39
|
+
const needsWrap =
|
|
40
|
+
val == null ||
|
|
41
|
+
typeof val !== 'object' ||
|
|
42
|
+
(f.type === 'content' && 'type' in (val as Record<string, unknown>));
|
|
43
|
+
if (needsWrap) {
|
|
44
|
+
const fallback = val ?? (f.type === 'content' ? null : '');
|
|
45
|
+
result[key] = Object.fromEntries(langs.map((l) => [l, fallback]));
|
|
39
46
|
}
|
|
40
47
|
} else if (f.type === 'url') {
|
|
41
48
|
const v = result[key] as Record<string, unknown> | undefined;
|
|
@@ -89,9 +96,9 @@
|
|
|
89
96
|
for (const f of fields) {
|
|
90
97
|
const key = f.slug;
|
|
91
98
|
const val = result[key];
|
|
92
|
-
if (['text', 'richtext'].includes(f.type)) {
|
|
99
|
+
if (['text', 'richtext', 'content'].includes(f.type)) {
|
|
93
100
|
if (val && typeof val === 'object' && !Array.isArray(val)) {
|
|
94
|
-
result[key] = (val as Record<string, unknown>)[currentLang] ?? '';
|
|
101
|
+
result[key] = (val as Record<string, unknown>)[currentLang] ?? (f.type === 'content' ? null : '');
|
|
95
102
|
}
|
|
96
103
|
} else if (f.type === 'url' && val && typeof val === 'object') {
|
|
97
104
|
const v = val as Record<string, unknown>;
|
|
@@ -84,8 +84,17 @@
|
|
|
84
84
|
element: bubbleMenu!
|
|
85
85
|
}),
|
|
86
86
|
Placeholder.configure({
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
showOnlyCurrent: false,
|
|
88
|
+
placeholder: ({ node, hasAnchor, editor }) => {
|
|
89
|
+
const isLastNode = editor.state.doc.lastChild === node;
|
|
90
|
+
if (isLastNode && node.type.name === 'paragraph') {
|
|
91
|
+
return 'Wpisz treść lub "/" by wstawić element';
|
|
92
|
+
}
|
|
93
|
+
if (hasAnchor) {
|
|
94
|
+
return 'Wpisz treść...';
|
|
95
|
+
}
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
89
98
|
})
|
|
90
99
|
],
|
|
91
100
|
content: initialContent,
|
|
@@ -310,7 +310,8 @@ div[data-collapsible]:not([data-collapsible='icon'])
|
|
|
310
310
|
|
|
311
311
|
/* Placeholder — Notion-style */
|
|
312
312
|
.ProseMirror .is-empty.is-editor-empty::before,
|
|
313
|
-
.ProseMirror .has-focus.is-empty::before
|
|
313
|
+
.ProseMirror .has-focus.is-empty::before,
|
|
314
|
+
.ProseMirror > .is-empty:last-child[data-placeholder]::before {
|
|
314
315
|
color: var(--text-light);
|
|
315
316
|
content: attr(data-placeholder);
|
|
316
317
|
float: left;
|
package/dist/ai-claude/index.js
CHANGED
|
@@ -2,9 +2,15 @@ import { getCMS } from '../core/cms.js';
|
|
|
2
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
3
3
|
import sharp from 'sharp';
|
|
4
4
|
export function claudeAdapter(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let client = null;
|
|
6
|
+
function getClient() {
|
|
7
|
+
if (!client) {
|
|
8
|
+
if (!config.apiKey)
|
|
9
|
+
throw new Error('AI_CLAUDE_API_KEY is not set');
|
|
10
|
+
client = new Anthropic({ apiKey: config.apiKey });
|
|
11
|
+
}
|
|
12
|
+
return client;
|
|
13
|
+
}
|
|
8
14
|
return {
|
|
9
15
|
generateAltText: async (fileId) => {
|
|
10
16
|
const mediaFile = await getCMS().databaseAdapter.getMediaFile({
|
|
@@ -23,7 +29,7 @@ export function claudeAdapter(config) {
|
|
|
23
29
|
const pngBuffer = await sharp(fileBuffer).png().toBuffer();
|
|
24
30
|
const imageBase64 = pngBuffer.toString('base64');
|
|
25
31
|
const prompt = `Generate a concise and descriptive alt text for the following image file in polish language. The alt text should accurately describe the content and context of the image, be no longer than 125 characters, and avoid using phrases like "image of" or "picture of". Return only the alt text, nothing else.`;
|
|
26
|
-
const message = await
|
|
32
|
+
const message = await getClient().messages.create({
|
|
27
33
|
model: 'claude-haiku-4-5-20251001',
|
|
28
34
|
max_tokens: 256,
|
|
29
35
|
messages: [
|
package/dist/cli/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { scaffoldAdmin } from './scaffold/admin.js';
|
|
3
|
+
import { installPeers } from './install-peers.js';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
const args = process.argv.slice(2);
|
|
5
6
|
const command = args[0];
|
|
@@ -8,11 +9,13 @@ function printUsage() {
|
|
|
8
9
|
console.log(`Usage: includio <command>
|
|
9
10
|
|
|
10
11
|
Commands:
|
|
11
|
-
scaffold admin
|
|
12
|
+
scaffold admin Generate admin route files
|
|
13
|
+
install-peers Install missing peer dependencies
|
|
12
14
|
|
|
13
15
|
Options:
|
|
14
|
-
--force
|
|
15
|
-
--routes-dir
|
|
16
|
+
--force Overwrite existing files
|
|
17
|
+
--routes-dir Path to routes directory (default: src/routes)
|
|
18
|
+
--dry-run Show what would be installed (install-peers)
|
|
16
19
|
`);
|
|
17
20
|
}
|
|
18
21
|
if (command === 'scaffold' && subcommand === 'admin') {
|
|
@@ -22,6 +25,10 @@ if (command === 'scaffold' && subcommand === 'admin') {
|
|
|
22
25
|
console.log('Scaffolding admin routes...\n');
|
|
23
26
|
scaffoldAdmin({ routesDir, force });
|
|
24
27
|
}
|
|
28
|
+
else if (command === 'install-peers') {
|
|
29
|
+
const dryRun = args.includes('--dry-run');
|
|
30
|
+
installPeers({ dryRun });
|
|
31
|
+
}
|
|
25
32
|
else {
|
|
26
33
|
printUsage();
|
|
27
34
|
process.exit(command ? 1 : 0);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
function detectPackageManager() {
|
|
5
|
+
const cwd = process.cwd();
|
|
6
|
+
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml')))
|
|
7
|
+
return 'pnpm';
|
|
8
|
+
return 'npm';
|
|
9
|
+
}
|
|
10
|
+
function getProjectDeps() {
|
|
11
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
12
|
+
if (!fs.existsSync(pkgPath)) {
|
|
13
|
+
console.error('No package.json found in current directory.');
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
17
|
+
return { ...pkg.dependencies, ...pkg.devDependencies };
|
|
18
|
+
}
|
|
19
|
+
function getCmsPeerDeps() {
|
|
20
|
+
// Find includio-cms package.json in node_modules
|
|
21
|
+
const cmsPkgPath = path.join(process.cwd(), 'node_modules', 'includio-cms', 'package.json');
|
|
22
|
+
if (!fs.existsSync(cmsPkgPath)) {
|
|
23
|
+
console.error('includio-cms not found in node_modules. Run install first.');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const pkg = JSON.parse(fs.readFileSync(cmsPkgPath, 'utf-8'));
|
|
27
|
+
return pkg.peerDependencies || {};
|
|
28
|
+
}
|
|
29
|
+
export function installPeers(options = {}) {
|
|
30
|
+
const projectDeps = getProjectDeps();
|
|
31
|
+
const peerDeps = getCmsPeerDeps();
|
|
32
|
+
const missing = [];
|
|
33
|
+
for (const [name, version] of Object.entries(peerDeps)) {
|
|
34
|
+
if (!projectDeps[name]) {
|
|
35
|
+
missing.push(`${name}@${version}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (missing.length === 0) {
|
|
39
|
+
console.log('All peer dependencies already installed.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
console.log(`Missing peer dependencies:\n${missing.map((m) => ` ${m}`).join('\n')}\n`);
|
|
43
|
+
if (options.dryRun) {
|
|
44
|
+
console.log('Dry run — no changes made.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const pm = detectPackageManager();
|
|
48
|
+
const cmd = `${pm} add ${missing.join(' ')}`;
|
|
49
|
+
console.log(`Running: ${cmd}\n`);
|
|
50
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
51
|
+
console.log('\nPeer dependencies installed.');
|
|
52
|
+
}
|
|
@@ -3,15 +3,42 @@ import type { ConfigBase } from '../../types/config.js';
|
|
|
3
3
|
import type { Layout, LayoutNode } from '../../types/layout.js';
|
|
4
4
|
export declare function getFieldsFromConfig(config: ConfigBase): Field[];
|
|
5
5
|
export declare function hasLayout(config: ConfigBase): boolean;
|
|
6
|
-
/** Collect all field
|
|
6
|
+
/** Collect all field paths referenced in layout nodes (depth-first order).
|
|
7
|
+
* Supports both plain slugs ('title') and dot-notation ('hero.title'). */
|
|
7
8
|
export declare function collectFieldSlugs(nodes: LayoutNode[]): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a field definition by dot-notation path.
|
|
11
|
+
* E.g. 'companyInfo.contact.email' navigates: fields → companyInfo → fields → contact → fields → email
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveFieldByPath(fields: Field[], path: string): Field | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Collect all leaf field paths from field definitions (recursively flattens objects).
|
|
16
|
+
* E.g. an object 'hero' with fields 'title','image' → ['hero.title', 'hero.image']
|
|
17
|
+
* Non-object fields at top level → ['slug']
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectAllLeafPaths(fields: Field[], prefix?: string): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Identify top-level object slugs where ALL leaf fields are individually
|
|
22
|
+
* distributed across layout nodes (via dot-notation).
|
|
23
|
+
* These objects should suppress their own wrapper rendering.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDistributedObjectSlugs(nodes: LayoutNode[], fields: Field[]): Set<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Build SuperForm-compatible path for a dot-notation field reference.
|
|
28
|
+
* 'hero.title' → 'hero.data.title'
|
|
29
|
+
* 'hero.contact.email' → 'hero.data.contact.data.email'
|
|
30
|
+
* 'title' → 'title' (no change for top-level)
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildFormPath(dotPath: string): string;
|
|
8
33
|
export interface LayoutValidationError {
|
|
9
34
|
type: 'missing_field' | 'duplicate_field' | 'depth_exceeded' | 'columns_mismatch';
|
|
10
35
|
message: string;
|
|
11
36
|
}
|
|
12
|
-
/** Validate layout against fields — returns errors or empty array
|
|
37
|
+
/** Validate layout against fields — returns errors or empty array.
|
|
38
|
+
* Supports dot-notation paths (e.g. 'hero.title'). */
|
|
13
39
|
export declare function validateLayout(nodes: LayoutNode[], fields: Field[]): LayoutValidationError[];
|
|
14
40
|
/** Expand a preset into LayoutNode[] */
|
|
15
41
|
export declare function resolveLayout(layout: Layout, fields: Field[]): LayoutNode[];
|
|
16
|
-
/** Resolve layout + append orphan fields in a trailing section
|
|
42
|
+
/** Resolve layout + append orphan fields in a trailing section.
|
|
43
|
+
* Orphan detection works at leaf level — dot-notation refs count as covering their leaves. */
|
|
17
44
|
export declare function resolveLayoutWithOrphans(config: ConfigBase): LayoutNode[];
|
|
@@ -5,7 +5,8 @@ export function getFieldsFromConfig(config) {
|
|
|
5
5
|
export function hasLayout(config) {
|
|
6
6
|
return !!config.layout;
|
|
7
7
|
}
|
|
8
|
-
/** Collect all field
|
|
8
|
+
/** Collect all field paths referenced in layout nodes (depth-first order).
|
|
9
|
+
* Supports both plain slugs ('title') and dot-notation ('hero.title'). */
|
|
9
10
|
export function collectFieldSlugs(nodes) {
|
|
10
11
|
const slugs = [];
|
|
11
12
|
for (const node of nodes) {
|
|
@@ -18,28 +19,133 @@ export function collectFieldSlugs(nodes) {
|
|
|
18
19
|
}
|
|
19
20
|
return slugs;
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a field definition by dot-notation path.
|
|
24
|
+
* E.g. 'companyInfo.contact.email' navigates: fields → companyInfo → fields → contact → fields → email
|
|
25
|
+
*/
|
|
26
|
+
export function resolveFieldByPath(fields, path) {
|
|
27
|
+
const parts = path.split('.');
|
|
28
|
+
let current = fields;
|
|
29
|
+
for (let i = 0; i < parts.length; i++) {
|
|
30
|
+
const field = current.find((f) => f.slug === parts[i]);
|
|
31
|
+
if (!field)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (i === parts.length - 1)
|
|
34
|
+
return field;
|
|
35
|
+
if (field.type !== 'object' || !('fields' in field))
|
|
36
|
+
return undefined;
|
|
37
|
+
current = field.fields;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Collect all leaf field paths from field definitions (recursively flattens objects).
|
|
43
|
+
* E.g. an object 'hero' with fields 'title','image' → ['hero.title', 'hero.image']
|
|
44
|
+
* Non-object fields at top level → ['slug']
|
|
45
|
+
*/
|
|
46
|
+
export function collectAllLeafPaths(fields, prefix = '') {
|
|
47
|
+
const paths = [];
|
|
48
|
+
for (const f of fields) {
|
|
49
|
+
const fullPath = prefix ? `${prefix}.${f.slug}` : f.slug;
|
|
50
|
+
if (f.type === 'object' && 'fields' in f) {
|
|
51
|
+
paths.push(...collectAllLeafPaths(f.fields, fullPath));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
paths.push(fullPath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return paths;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Expand a layout field reference into leaf paths.
|
|
61
|
+
* - 'title' (non-object) → ['title']
|
|
62
|
+
* - 'hero' (object with fields) → ['hero.title', 'hero.image', ...]
|
|
63
|
+
* - 'hero.title' (dot-notation to leaf) → ['hero.title']
|
|
64
|
+
*/
|
|
65
|
+
function expandToLeafPaths(ref, fields) {
|
|
66
|
+
const resolved = resolveFieldByPath(fields, ref);
|
|
67
|
+
if (!resolved)
|
|
68
|
+
return [ref]; // unresolved — let validation catch it
|
|
69
|
+
if (resolved.type === 'object' && 'fields' in resolved) {
|
|
70
|
+
return collectAllLeafPaths(resolved.fields, ref);
|
|
71
|
+
}
|
|
72
|
+
return [ref];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Identify top-level object slugs where ALL leaf fields are individually
|
|
76
|
+
* distributed across layout nodes (via dot-notation).
|
|
77
|
+
* These objects should suppress their own wrapper rendering.
|
|
78
|
+
*/
|
|
79
|
+
export function getDistributedObjectSlugs(nodes, fields) {
|
|
80
|
+
const refs = collectFieldSlugs(nodes);
|
|
81
|
+
const distributed = new Set();
|
|
82
|
+
for (const f of fields) {
|
|
83
|
+
if (f.type !== 'object' || !('fields' in f))
|
|
84
|
+
continue;
|
|
85
|
+
// Check: is this object referenced as a whole?
|
|
86
|
+
if (refs.includes(f.slug))
|
|
87
|
+
continue;
|
|
88
|
+
// Get all leaf paths for this object
|
|
89
|
+
const leafPaths = collectAllLeafPaths(f.fields, f.slug);
|
|
90
|
+
if (leafPaths.length === 0)
|
|
91
|
+
continue;
|
|
92
|
+
// Check if ALL leaf paths are covered by layout refs
|
|
93
|
+
const allCovered = leafPaths.every((lp) => refs.includes(lp));
|
|
94
|
+
if (allCovered)
|
|
95
|
+
distributed.add(f.slug);
|
|
96
|
+
}
|
|
97
|
+
return distributed;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Build SuperForm-compatible path for a dot-notation field reference.
|
|
101
|
+
* 'hero.title' → 'hero.data.title'
|
|
102
|
+
* 'hero.contact.email' → 'hero.data.contact.data.email'
|
|
103
|
+
* 'title' → 'title' (no change for top-level)
|
|
104
|
+
*/
|
|
105
|
+
export function buildFormPath(dotPath) {
|
|
106
|
+
const parts = dotPath.split('.');
|
|
107
|
+
if (parts.length <= 1)
|
|
108
|
+
return dotPath;
|
|
109
|
+
const result = [parts[0]];
|
|
110
|
+
for (let i = 1; i < parts.length; i++) {
|
|
111
|
+
result.push('data', parts[i]);
|
|
112
|
+
}
|
|
113
|
+
return result.join('.');
|
|
114
|
+
}
|
|
21
115
|
/** Count columns expected by a ratio string */
|
|
22
116
|
function columnCount(ratio) {
|
|
23
117
|
return ratio.split(' ').length;
|
|
24
118
|
}
|
|
25
|
-
/** Validate layout against fields — returns errors or empty array
|
|
119
|
+
/** Validate layout against fields — returns errors or empty array.
|
|
120
|
+
* Supports dot-notation paths (e.g. 'hero.title'). */
|
|
26
121
|
export function validateLayout(nodes, fields) {
|
|
27
122
|
const errors = [];
|
|
28
|
-
const
|
|
123
|
+
const topLevelSlugs = new Set(fields.map((f) => f.slug));
|
|
29
124
|
const referencedSlugs = collectFieldSlugs(nodes);
|
|
30
|
-
// Check for missing fields
|
|
125
|
+
// Check for missing fields — support both top-level slugs and dot-notation
|
|
31
126
|
for (const slug of referencedSlugs) {
|
|
32
|
-
if (
|
|
33
|
-
|
|
127
|
+
if (slug.includes('.')) {
|
|
128
|
+
// Dot-notation: resolve through field tree
|
|
129
|
+
if (!resolveFieldByPath(fields, slug)) {
|
|
130
|
+
errors.push({ type: 'missing_field', message: `Field "${slug}" not found in fields[]` });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
if (!topLevelSlugs.has(slug)) {
|
|
135
|
+
errors.push({ type: 'missing_field', message: `Field "${slug}" not found in fields[]` });
|
|
136
|
+
}
|
|
34
137
|
}
|
|
35
138
|
}
|
|
36
|
-
// Check for duplicates
|
|
37
|
-
const
|
|
38
|
-
for (const
|
|
39
|
-
|
|
40
|
-
|
|
139
|
+
// Check for duplicates (expand to leaf paths for overlap detection)
|
|
140
|
+
const seenLeaves = new Set();
|
|
141
|
+
for (const ref of referencedSlugs) {
|
|
142
|
+
const leaves = expandToLeafPaths(ref, fields);
|
|
143
|
+
for (const leaf of leaves) {
|
|
144
|
+
if (seenLeaves.has(leaf)) {
|
|
145
|
+
errors.push({ type: 'duplicate_field', message: `Field "${leaf}" referenced multiple times` });
|
|
146
|
+
}
|
|
147
|
+
seenLeaves.add(leaf);
|
|
41
148
|
}
|
|
42
|
-
seen.add(slug);
|
|
43
149
|
}
|
|
44
150
|
// Check depth + columns
|
|
45
151
|
function walk(nodeList, depth) {
|
|
@@ -72,7 +178,8 @@ export function resolveLayout(layout, fields) {
|
|
|
72
178
|
return layout;
|
|
73
179
|
return expandPreset(layout, fields);
|
|
74
180
|
}
|
|
75
|
-
/** Resolve layout + append orphan fields in a trailing section
|
|
181
|
+
/** Resolve layout + append orphan fields in a trailing section.
|
|
182
|
+
* Orphan detection works at leaf level — dot-notation refs count as covering their leaves. */
|
|
76
183
|
export function resolveLayoutWithOrphans(config) {
|
|
77
184
|
if (!config.layout) {
|
|
78
185
|
// No layout — single section with all fields
|
|
@@ -85,16 +192,37 @@ export function resolveLayoutWithOrphans(config) {
|
|
|
85
192
|
];
|
|
86
193
|
}
|
|
87
194
|
const nodes = resolveLayout(config.layout, config.fields);
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
195
|
+
const refs = collectFieldSlugs(nodes);
|
|
196
|
+
// Expand all refs to leaf paths for coverage checking
|
|
197
|
+
const coveredLeaves = new Set();
|
|
198
|
+
for (const ref of refs) {
|
|
199
|
+
for (const leaf of expandToLeafPaths(ref, config.fields)) {
|
|
200
|
+
coveredLeaves.add(leaf);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Find orphan top-level fields (not covered at all)
|
|
204
|
+
const allLeaves = collectAllLeafPaths(config.fields);
|
|
205
|
+
const orphanTopSlugs = [];
|
|
206
|
+
for (const f of config.fields) {
|
|
207
|
+
if (f.type === 'object' && 'fields' in f) {
|
|
208
|
+
const objectLeaves = collectAllLeafPaths(f.fields, f.slug);
|
|
209
|
+
const anyCovered = objectLeaves.some((lp) => coveredLeaves.has(lp));
|
|
210
|
+
if (!anyCovered)
|
|
211
|
+
orphanTopSlugs.push(f.slug);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
if (!coveredLeaves.has(f.slug))
|
|
215
|
+
orphanTopSlugs.push(f.slug);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (orphanTopSlugs.length === 0)
|
|
91
219
|
return nodes;
|
|
92
220
|
return [
|
|
93
221
|
...nodes,
|
|
94
222
|
{
|
|
95
223
|
type: 'section',
|
|
96
224
|
label: { en: 'Other', pl: 'Pozostałe' },
|
|
97
|
-
fields:
|
|
225
|
+
fields: orphanTopSlugs
|
|
98
226
|
}
|
|
99
227
|
];
|
|
100
228
|
}
|
|
@@ -31,7 +31,8 @@ function generateTypesStringForRecords(type, records) {
|
|
|
31
31
|
export type ${recordTypeString}EntryMap = {
|
|
32
32
|
${records
|
|
33
33
|
.map((single) => {
|
|
34
|
-
|
|
34
|
+
const key = single.slug.includes('-') ? `'${single.slug}'` : single.slug;
|
|
35
|
+
return `${key}: ${toPascalCase(single.slug)}`;
|
|
35
36
|
})
|
|
36
37
|
.join(';\n')}
|
|
37
38
|
}
|
|
@@ -58,7 +59,8 @@ function generateTypesStringForForms(records) {
|
|
|
58
59
|
export type ${recordTypeString}EntryMap = {
|
|
59
60
|
${records
|
|
60
61
|
.map((single) => {
|
|
61
|
-
|
|
62
|
+
const key = single.slug.includes('-') ? `'${single.slug}'` : single.slug;
|
|
63
|
+
return `${key}: ${toPascalCase(single.slug)}`;
|
|
62
64
|
})
|
|
63
65
|
.join(';\n')}
|
|
64
66
|
}
|
|
@@ -94,10 +96,10 @@ function generateAPI(config) {
|
|
|
94
96
|
`;
|
|
95
97
|
code += `
|
|
96
98
|
|
|
97
|
-
interface GetEntryQueryOptions
|
|
99
|
+
interface GetEntryQueryOptions {
|
|
98
100
|
id?: string;
|
|
99
101
|
status?: 'draft' | 'published' | 'scheduled' | 'archived';
|
|
100
|
-
dataValues?:
|
|
102
|
+
dataValues?: Record<string, unknown>;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
interface GetEntryOptions {
|
|
@@ -118,7 +120,7 @@ function generateAPI(config) {
|
|
|
118
120
|
`;
|
|
119
121
|
code += `
|
|
120
122
|
|
|
121
|
-
export async function getSingleEntry<K extends SingleSlug>(slug: K, data: GetEntryQueryOptions
|
|
123
|
+
export async function getSingleEntry<K extends SingleSlug>(slug: K, data: GetEntryQueryOptions, options: GetEntryOptions): Promise<SingleEntryMap[K] | null> {
|
|
122
124
|
return (await getEntry({
|
|
123
125
|
...data,
|
|
124
126
|
slug,
|
|
@@ -126,7 +128,7 @@ function generateAPI(config) {
|
|
|
126
128
|
})) as unknown as SingleEntryMap[K] | null;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
export async function getCollectionEntry<K extends CollectionSlug>(slug: K, data: GetEntryQueryOptions
|
|
131
|
+
export async function getCollectionEntry<K extends CollectionSlug>(slug: K, data: GetEntryQueryOptions, options: GetEntryOptions): Promise<CollectionEntryMap[K] | null> {
|
|
130
132
|
return (await getEntry({
|
|
131
133
|
...data,
|
|
132
134
|
slug,
|
|
@@ -134,7 +136,15 @@ function generateAPI(config) {
|
|
|
134
136
|
})) as unknown as CollectionEntryMap[K] | null;
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
interface GetEntriesQueryOptions {
|
|
140
|
+
ids?: string[];
|
|
141
|
+
status?: 'draft' | 'published' | 'scheduled' | 'archived';
|
|
142
|
+
dataValues?: Record<string, unknown>;
|
|
143
|
+
dataLike?: Record<string, unknown>;
|
|
144
|
+
orderBy?: { column: 'createdAt' | 'updatedAt' | 'sortOrder'; direction: 'asc' | 'desc' };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function getCollectionEntries<K extends CollectionSlug>(slug: K, options: GetEntryOptions & GetEntriesQueryOptions = {}): Promise<CollectionEntryMap[K][]> {
|
|
138
148
|
return (await getEntries({ slug, ...options })) as unknown as CollectionEntryMap[K][];
|
|
139
149
|
}
|
|
140
150
|
|
|
@@ -162,8 +172,9 @@ function generateSchemas(config) {
|
|
|
162
172
|
import { z } from 'zod';
|
|
163
173
|
`;
|
|
164
174
|
config.forms?.map((form) => {
|
|
175
|
+
const varName = toPascalCase(form.slug);
|
|
165
176
|
code += `
|
|
166
|
-
export const ${
|
|
177
|
+
export const ${varName}FormSchema = ${generateZodSchemaStringFromFormFieldsAsString(form.fields)} \n
|
|
167
178
|
`;
|
|
168
179
|
});
|
|
169
180
|
writeFileSync(filePath, code);
|
|
@@ -177,13 +188,13 @@ function generateRemote(config) {
|
|
|
177
188
|
code += `import { command } from '$app/server';\n`;
|
|
178
189
|
code += `import { submitForm } from './api';\n`;
|
|
179
190
|
const schemaImports = config.forms
|
|
180
|
-
.map((form) => `${form.slug}FormSchema`)
|
|
191
|
+
.map((form) => `${toPascalCase(form.slug)}FormSchema`)
|
|
181
192
|
.join(', ');
|
|
182
193
|
code += `import { ${schemaImports} } from './schemas';\n\n`;
|
|
183
194
|
config.forms.forEach((form) => {
|
|
184
195
|
const pascalSlug = toPascalCase(form.slug);
|
|
185
196
|
code += `export const submit${pascalSlug}Command = command(\n`;
|
|
186
|
-
code += `\t${
|
|
197
|
+
code += `\t${pascalSlug}FormSchema,\n`;
|
|
187
198
|
code += `\tasync (data) => {\n`;
|
|
188
199
|
code += `\t\tawait submitForm('${form.slug}', data);\n`;
|
|
189
200
|
code += `\t}\n`;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CMS } from '../core/cms.js';
|
|
2
|
+
import type { DbEntry, DbEntryVersion, EntryData } from '../types/entries.js';
|
|
3
|
+
interface EntityAPIOptions {
|
|
4
|
+
userId?: string;
|
|
5
|
+
}
|
|
6
|
+
interface CreateOptions {
|
|
7
|
+
skipValidation?: boolean;
|
|
8
|
+
sortOrder?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function createEntityAPI(cms: CMS, opts?: EntityAPIOptions): {
|
|
11
|
+
create(slug: string, data?: EntryData, options?: CreateOptions): Promise<DbEntry>;
|
|
12
|
+
update(entryId: string, data: EntryData, options?: {
|
|
13
|
+
skipValidation?: boolean;
|
|
14
|
+
}): Promise<DbEntryVersion>;
|
|
15
|
+
publish(entryId: string): Promise<void>;
|
|
16
|
+
unpublish(entryId: string): Promise<void>;
|
|
17
|
+
archive(entryId: string): Promise<void>;
|
|
18
|
+
unarchive(entryId: string): Promise<void>;
|
|
19
|
+
delete(entryId: string): Promise<void>;
|
|
20
|
+
list(slug: string, options?: {
|
|
21
|
+
includeArchived?: boolean;
|
|
22
|
+
onlyArchived?: boolean;
|
|
23
|
+
}): Promise<import("../types/entries.js").RawEntry[]>;
|
|
24
|
+
createAndPublish(slug: string, data: EntryData, options?: CreateOptions): Promise<DbEntry>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|