@oktis-works/validation 0.8.1 → 0.9.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 +157 -0
- package/dist/compatibility.d.ts +1 -1
- package/dist/compatibility.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/theme-manifest.d.ts +23 -0
- package/dist/theme-manifest.d.ts.map +1 -0
- package/dist/theme-manifest.js +56 -0
- package/dist/theme-manifest.js.map +1 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @oktis-works/validation
|
|
2
|
+
|
|
3
|
+
Field validation — field groups, logical values, custom field support.
|
|
4
|
+
|
|
5
|
+
## Core Concepts
|
|
6
|
+
|
|
7
|
+
### Field Groups
|
|
8
|
+
|
|
9
|
+
Logical collections of fields attached to content types.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
interface FieldGroup {
|
|
13
|
+
key: string; // 'seo', 'hero', 'custom'
|
|
14
|
+
title: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
position: 'normal' | 'side' | 'advanced';
|
|
17
|
+
displayStyle: 'standard' | 'accordion' | 'tabs';
|
|
18
|
+
fields: FieldDefinition[];
|
|
19
|
+
active: boolean;
|
|
20
|
+
attachTo: string[]; // content type slugs
|
|
21
|
+
source: 'CORE' | 'PLUGIN' | 'ADMIN';
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Field Definitions
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
interface FieldDefinition {
|
|
29
|
+
name: string; // unique within group
|
|
30
|
+
label: string;
|
|
31
|
+
type: string; // 'text', 'textarea', 'select', 'media', 'repeater', 'custom', etc.
|
|
32
|
+
required?: boolean;
|
|
33
|
+
defaultValue?: unknown;
|
|
34
|
+
options?: Record<string, unknown>; // select options, validation rules, etc.
|
|
35
|
+
validation?: ValidationRule[];
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Validation Rules
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
interface ValidationRule {
|
|
43
|
+
type: 'required' | 'minLength' | 'maxLength' | 'pattern' | 'custom';
|
|
44
|
+
params?: Record<string, unknown>;
|
|
45
|
+
message?: string;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Logical Values Normalization
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
function normalizeLogicalValues(input: {
|
|
53
|
+
body?: Record<string, unknown>;
|
|
54
|
+
data?: Record<string, unknown>;
|
|
55
|
+
native?: Record<string, unknown>;
|
|
56
|
+
}): Record<string, unknown>;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- Merges `body` (editor content), `data` (custom fields), `native` (direct fields)
|
|
60
|
+
- Resolves field groups into flat logical values
|
|
61
|
+
- Used before save and before render
|
|
62
|
+
|
|
63
|
+
## Body Serialization
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
function logicalValuesToBody(logical: Record<string, unknown>): Record<string, unknown>;
|
|
67
|
+
function logicalValuesToNative(logical: Record<string, unknown>): Record<string, unknown>;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- `logicalValuesToBody` → JSONB stored in `content.body`
|
|
71
|
+
- `logicalValuesToNative` → flat object for template context
|
|
72
|
+
|
|
73
|
+
## Field Group Service
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
class FieldGroupService {
|
|
77
|
+
async list(type: string): Promise<ResolvedFieldGroup[]>;
|
|
78
|
+
async get(key: string): Promise<FieldGroup | null>;
|
|
79
|
+
async validateValues(context: { contentType: string; contentSlug?: string; postStatus?: string }, values: Record<string, unknown>): Promise<ValidationIssue[]>;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Custom Fields (Phase 4)
|
|
84
|
+
|
|
85
|
+
Custom field types from plugins:
|
|
86
|
+
|
|
87
|
+
1. Registered via `api.addFieldType()` in plugin SDK
|
|
88
|
+
2. Stored in `field_type_extensions` table
|
|
89
|
+
3. Loaded by `FieldGroupService` alongside core fields
|
|
90
|
+
4. Config validated against `configSchema` (JSON Schema)
|
|
91
|
+
5. Rendered in admin via dynamic import of `adminComponentPath`
|
|
92
|
+
6. Frontend render via `adminRendererPath` (or fallback)
|
|
93
|
+
|
|
94
|
+
## Phase 1 Integration
|
|
95
|
+
|
|
96
|
+
- Parent field (`parentId`) added to content create/update
|
|
97
|
+
- Validation ensures same type, same tenant, no cycles, max depth 5
|
|
98
|
+
- Logical values include `parentId` in native object
|
|
99
|
+
|
|
100
|
+
## Custom Field Registration (Plugin SDK)
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
api.addFieldType({
|
|
104
|
+
type: 'my_custom_field',
|
|
105
|
+
label: 'My Custom Field',
|
|
106
|
+
category: 'media',
|
|
107
|
+
icon: 'image',
|
|
108
|
+
adminComponentPath: './admin/components/MyField.tsx',
|
|
109
|
+
adminRendererPath: './admin/components/MyFieldRenderer.tsx',
|
|
110
|
+
configSchema: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
option1: { type: 'string', title: 'Option 1' }
|
|
114
|
+
},
|
|
115
|
+
required: ['option1']
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Field Groups in Templates
|
|
121
|
+
|
|
122
|
+
Available as `fields` object in template context:
|
|
123
|
+
|
|
124
|
+
```astro
|
|
125
|
+
---
|
|
126
|
+
const { fields } = Astro.props;
|
|
127
|
+
---
|
|
128
|
+
<div class="hero">
|
|
129
|
+
<h1>{fields.hero?.title}</h1>
|
|
130
|
+
<img src={fields.hero?.image?.url} alt={fields.hero?.image?.alt} />
|
|
131
|
+
</div>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Field Group Positions
|
|
135
|
+
|
|
136
|
+
| Position | Use Case |
|
|
137
|
+
|----------|----------|
|
|
138
|
+
| `normal` | Main content area (below editor) |
|
|
139
|
+
| `side` | Sidebar (publish panel, attributes) |
|
|
140
|
+
| `advanced` | Collapsed advanced section |
|
|
141
|
+
|
|
142
|
+
## Display Styles
|
|
143
|
+
|
|
144
|
+
| Style | Behavior |
|
|
145
|
+
|-------|----------|
|
|
146
|
+
| `standard` | Fields stacked vertically |
|
|
147
|
+
| `accordion` | Collapsible sections |
|
|
148
|
+
| `tabs` | Tabbed interface |
|
|
149
|
+
|
|
150
|
+
## Validation Flow
|
|
151
|
+
|
|
152
|
+
1. **Admin save** → `stripUnsupportedFields` (removes unsupported fields per type)
|
|
153
|
+
2. **Hook** → `before_save_content:{type}` filter
|
|
154
|
+
3. **Normalize** → `normalizeLogicalValues` merges body/data/native
|
|
155
|
+
4. **Validate** → `validateCustomFields` against field group schemas
|
|
156
|
+
5. **Serialize** → `logicalValuesToBody` → stored in `content.body`
|
|
157
|
+
6. **Native** → `logicalValuesToNative` → template context
|
package/dist/compatibility.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface CompatibilityIssue {
|
|
|
11
11
|
message: string;
|
|
12
12
|
}
|
|
13
13
|
/** Versão do CMS contra a qual a compatibilidade é avaliada. */
|
|
14
|
-
export declare const CMS_VERSION = "0.
|
|
14
|
+
export declare const CMS_VERSION = "0.42.2";
|
|
15
15
|
/**
|
|
16
16
|
* Valida o manifesto de uma extensão (plugin|theme) contra a versão do CMS.
|
|
17
17
|
* BUSI-022: manifest deve conter name, version, type e compatibility.okcms;
|
package/dist/compatibility.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @oktis-works/validation - Extension Compatibility (BUSI-022 / RULE-semver-compatibility)
|
|
2
2
|
import { satisfies, validRange } from 'semver';
|
|
3
3
|
/** Versão do CMS contra a qual a compatibilidade é avaliada. */
|
|
4
|
-
export const CMS_VERSION = '0.
|
|
4
|
+
export const CMS_VERSION = '0.42.2';
|
|
5
5
|
/**
|
|
6
6
|
* Valida o manifesto de uma extensão (plugin|theme) contra a versão do CMS.
|
|
7
7
|
* BUSI-022: manifest deve conter name, version, type e compatibility.okcms;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export { CANONICAL_CORE_FIELDS, CANONICAL_FIELD_ALIASES, canonicalFieldName, log
|
|
|
14
14
|
export { findFieldPathIssues } from './field-paths.js';
|
|
15
15
|
export type { FieldPathDefinition } from './field-paths.js';
|
|
16
16
|
export type { CanonicalCoreField, LogicalValueRecord, LogicalValueSources, } from './field-values.js';
|
|
17
|
+
export { validateThemeRenderConfig, validateThemeManifestRender, isSafeThemeRenderEntry, } from './theme-manifest.js';
|
|
18
|
+
export type { ThemeRenderEngine, ThemeRenderConfigLike, ThemeRenderManifestLike, } from './theme-manifest.js';
|
|
17
19
|
export { PLUGIN_PERMISSIONS, PLUGIN_PERMISSION_DEFAULT, isKnownPluginPermission, unknownPluginPermissions, resolvePluginPermissionPolicy, } from './plugin-permissions.js';
|
|
18
20
|
export type { PluginPermission, PermissionPolicy } from './plugin-permissions.js';
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,qBAAq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AgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,5 +11,6 @@ export { evaluateConditionalLogic, findConditionalIssues, isVisibleField } from
|
|
|
11
11
|
export { expandCloneFields } from './clone.js';
|
|
12
12
|
export { CANONICAL_CORE_FIELDS, CANONICAL_FIELD_ALIASES, canonicalFieldName, logicalValuesToBody, logicalValuesToNative, normalizeLogicalValues, } from './field-values.js';
|
|
13
13
|
export { findFieldPathIssues } from './field-paths.js';
|
|
14
|
+
export { validateThemeRenderConfig, validateThemeManifestRender, isSafeThemeRenderEntry, } from './theme-manifest.js';
|
|
14
15
|
export { PLUGIN_PERMISSIONS, PLUGIN_PERMISSION_DEFAULT, isKnownPluginPermission, unknownPluginPermissions, resolvePluginPermissionPolicy, } from './plugin-permissions.js';
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uFAAuF;AAEvF,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOvD,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uFAAuF;AAEvF,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOvD,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ThemeRenderEngine = 'template' | 'react' | 'solid';
|
|
2
|
+
export interface ThemeRenderConfigLike {
|
|
3
|
+
engine?: unknown;
|
|
4
|
+
apiVersion?: unknown;
|
|
5
|
+
hydration?: unknown;
|
|
6
|
+
entry?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface ThemeRenderManifestLike {
|
|
9
|
+
name?: unknown;
|
|
10
|
+
version?: unknown;
|
|
11
|
+
type?: unknown;
|
|
12
|
+
render?: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** A render entry must stay inside the theme and be a relative path. */
|
|
15
|
+
export declare function isSafeThemeRenderEntry(value: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Validates a `theme.json` `render` object.
|
|
18
|
+
* An absent value is valid and means the legacy template engine.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateThemeRenderConfig(render: unknown): string[];
|
|
21
|
+
/** Validates the render-related portion of a complete theme manifest. */
|
|
22
|
+
export declare function validateThemeManifestRender(manifest: unknown): string[];
|
|
23
|
+
//# sourceMappingURL=theme-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-manifest.d.ts","sourceRoot":"","sources":["../src/theme-manifest.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/D,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAID,wEAAwE;AACxE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK7D;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CA6BnE;AAED,yEAAyE;AACzE,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CASvE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @oktis-works/validation - Theme render contract validation
|
|
2
|
+
//
|
|
3
|
+
// Shared by core (install/sync), the CLI (scaffold/build), the theme runtime
|
|
4
|
+
// (discovery) and the web app (parent manifests). Pure: no filesystem access.
|
|
5
|
+
const VALID_ENGINES = ['template', 'react', 'solid'];
|
|
6
|
+
/** A render entry must stay inside the theme and be a relative path. */
|
|
7
|
+
export function isSafeThemeRenderEntry(value) {
|
|
8
|
+
if (!value || value.length > 300)
|
|
9
|
+
return false;
|
|
10
|
+
if (value.includes('..') || value.includes('\\') || value.includes('://'))
|
|
11
|
+
return false;
|
|
12
|
+
if (value.startsWith('/') || value.startsWith('~'))
|
|
13
|
+
return false;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates a `theme.json` `render` object.
|
|
18
|
+
* An absent value is valid and means the legacy template engine.
|
|
19
|
+
*/
|
|
20
|
+
export function validateThemeRenderConfig(render) {
|
|
21
|
+
if (render === undefined || render === null)
|
|
22
|
+
return [];
|
|
23
|
+
if (typeof render !== 'object' || Array.isArray(render)) {
|
|
24
|
+
return ['render must be an object'];
|
|
25
|
+
}
|
|
26
|
+
const config = render;
|
|
27
|
+
const issues = [];
|
|
28
|
+
const engine = config.engine ?? 'template';
|
|
29
|
+
if (typeof engine !== 'string' || !VALID_ENGINES.includes(engine)) {
|
|
30
|
+
issues.push(`render.engine must be one of: ${VALID_ENGINES.join(', ')}`);
|
|
31
|
+
}
|
|
32
|
+
if (config.apiVersion !== undefined && config.apiVersion !== 1) {
|
|
33
|
+
issues.push('render.apiVersion must be 1');
|
|
34
|
+
}
|
|
35
|
+
if (config.hydration !== undefined && config.hydration !== 'none' && config.hydration !== 'islands') {
|
|
36
|
+
issues.push('render.hydration must be "none" or "islands"');
|
|
37
|
+
}
|
|
38
|
+
if (config.entry !== undefined) {
|
|
39
|
+
if (typeof config.entry !== 'string' || !isSafeThemeRenderEntry(config.entry)) {
|
|
40
|
+
issues.push('render.entry must be a safe relative path inside the theme');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return issues;
|
|
44
|
+
}
|
|
45
|
+
/** Validates the render-related portion of a complete theme manifest. */
|
|
46
|
+
export function validateThemeManifestRender(manifest) {
|
|
47
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) {
|
|
48
|
+
return ['theme manifest must be an object'];
|
|
49
|
+
}
|
|
50
|
+
const record = manifest;
|
|
51
|
+
if (record.type !== undefined && record.type !== 'theme') {
|
|
52
|
+
return ['theme manifest type must be "theme"'];
|
|
53
|
+
}
|
|
54
|
+
return validateThemeRenderConfig(record.render);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=theme-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-manifest.js","sourceRoot":"","sources":["../src/theme-manifest.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAkB9E,MAAM,aAAa,GAAiC,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAEnF,wEAAwE;AACxE,MAAM,UAAU,sBAAsB,CAAC,KAAa;IAClD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxF,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACjE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAe;IACvD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACvD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,MAAM,GAAG,MAA+B,CAAC;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,UAAU,CAAC;IAE3C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAA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