@opencloudcms/schema 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/__typecheck__/define-messages.d.ts +20 -0
- package/dist/__typecheck__/define-messages.js +16 -0
- package/dist/__typecheck__/define-messages.js.map +1 -0
- package/dist/actions.d.ts +86 -0
- package/dist/actions.js +158 -0
- package/dist/actions.js.map +1 -0
- package/dist/composed-block.d.ts +205 -0
- package/dist/composed-block.js +897 -0
- package/dist/composed-block.js.map +1 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +57 -0
- package/dist/config.js.map +1 -0
- package/dist/define.d.ts +31 -0
- package/dist/define.js +113 -0
- package/dist/define.js.map +1 -0
- package/dist/form-controls.d.ts +18 -0
- package/dist/form-controls.js +52 -0
- package/dist/form-controls.js.map +1 -0
- package/dist/groups.d.ts +12 -0
- package/dist/groups.js +55 -0
- package/dist/groups.js.map +1 -0
- package/dist/i18n.d.ts +43 -0
- package/dist/i18n.js +93 -0
- package/dist/i18n.js.map +1 -0
- package/dist/icons.d.ts +3 -0
- package/dist/icons.js +28 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/locales.d.ts +11 -0
- package/dist/locales.js +38 -0
- package/dist/locales.js.map +1 -0
- package/dist/pages.d.ts +78 -0
- package/dist/pages.js +139 -0
- package/dist/pages.js.map +1 -0
- package/dist/permissions.d.ts +7 -0
- package/dist/permissions.js +29 -0
- package/dist/permissions.js.map +1 -0
- package/dist/physical.d.ts +72 -0
- package/dist/physical.js +195 -0
- package/dist/physical.js.map +1 -0
- package/dist/search.d.ts +5 -0
- package/dist/search.js +15 -0
- package/dist/search.js.map +1 -0
- package/dist/slug.d.ts +65 -0
- package/dist/slug.js +238 -0
- package/dist/slug.js.map +1 -0
- package/dist/style.d.ts +71 -0
- package/dist/style.js +211 -0
- package/dist/style.js.map +1 -0
- package/dist/theme.d.ts +15 -0
- package/dist/theme.js +64 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +11 -0
- package/dist/validate.js +191 -0
- package/dist/validate.js.map +1 -0
- package/dist/validator.d.ts +25 -0
- package/dist/validator.js +80 -0
- package/dist/validator.js.map +1 -0
- package/package.json +30 -3
package/dist/icons.d.ts
ADDED
package/dist/icons.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Curated icon names (kebab-case lucide names) for the Icon element and Button icons. Plain strings: the schema
|
|
3
|
+
// imports no icon library; the blocks UI maps each name to an explicitly imported component.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ICON_NAMES = void 0;
|
|
6
|
+
exports.isIconName = isIconName;
|
|
7
|
+
/** At most 80 names, nav and commerce first. */
|
|
8
|
+
exports.ICON_NAMES = [
|
|
9
|
+
// navigation
|
|
10
|
+
'menu', 'x', 'chevron-down', 'chevron-up', 'chevron-left', 'chevron-right', 'arrow-right', 'arrow-left', 'arrow-up-right',
|
|
11
|
+
'search', 'home', 'external-link', 'link', 'list', 'layout-grid', 'filter', 'sliders-horizontal',
|
|
12
|
+
// commerce
|
|
13
|
+
'shopping-cart', 'shopping-bag', 'package', 'store', 'truck', 'credit-card', 'gift', 'tag', 'percent', 'heart', 'star',
|
|
14
|
+
// people and contact
|
|
15
|
+
'user', 'users', 'phone', 'mail', 'map-pin', 'map', 'message-circle', 'send', 'bell', 'globe',
|
|
16
|
+
// time
|
|
17
|
+
'clock', 'calendar',
|
|
18
|
+
// status
|
|
19
|
+
'check', 'check-circle', 'info', 'alert-circle', 'help-circle', 'plus', 'minus', 'shield-check', 'award', 'zap', 'thumbs-up',
|
|
20
|
+
// actions and media
|
|
21
|
+
'share-2', 'download', 'play', 'pause', 'image', 'bookmark', 'eye', 'lock', 'settings', 'log-in', 'log-out', 'sun', 'moon',
|
|
22
|
+
// social
|
|
23
|
+
'facebook', 'instagram', 'youtube', 'twitter', 'linkedin', 'github',
|
|
24
|
+
];
|
|
25
|
+
function isIconName(v) {
|
|
26
|
+
return typeof v === 'string' && exports.ICON_NAMES.includes(v);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js","sourceRoot":"","sources":["../src/icons.ts"],"names":[],"mappings":";AAAA,gHAAgH;AAChH,6FAA6F;;;AAqB7F,gCAEC;AArBD,gDAAgD;AACnC,QAAA,UAAU,GAAsB;IAC3C,aAAa;IACb,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB;IACzH,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,oBAAoB;IAChG,WAAW;IACX,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;IACtH,qBAAqB;IACrB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAC7F,OAAO;IACP,OAAO,EAAE,UAAU;IACnB,SAAS;IACT,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW;IAC5H,oBAAoB;IACpB,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM;IAC1H,SAAS;IACT,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ;CACpE,CAAC;AAEF,SAAgB,UAAU,CAAC,CAAU;IACnC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,kBAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './define';
|
|
3
|
+
export * from './physical';
|
|
4
|
+
export * from './validate';
|
|
5
|
+
export * from './validator';
|
|
6
|
+
export * from './config';
|
|
7
|
+
export * from './i18n';
|
|
8
|
+
export * from './locales';
|
|
9
|
+
export * from './groups';
|
|
10
|
+
export * from './permissions';
|
|
11
|
+
export * from './pages';
|
|
12
|
+
export * from './actions';
|
|
13
|
+
export * from './composed-block';
|
|
14
|
+
export { BREAKPOINTS, HOVER_ELEMENTS, STYLE_SPACING_TOKENS, STYLE_COLOR_TOKENS, RADIUS_TOKENS, BORDER_WIDTH_TOKENS, BORDER_SIDES, isLength, isColorValue, isTrack, resolveResponsive, valueAt, setAt, validateNodeStyle, } from './style';
|
|
15
|
+
export type { Breakpoint, Responsive, Length, ColorValue, Track, Sides, NodeStyle, HoverStyle } from './style';
|
|
16
|
+
export * from './icons';
|
|
17
|
+
export * from './form-controls';
|
|
18
|
+
export * from './theme';
|
|
19
|
+
export * from './search';
|
|
20
|
+
export * from './slug';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.validateNodeStyle = exports.setAt = exports.valueAt = exports.resolveResponsive = exports.isTrack = exports.isColorValue = exports.isLength = exports.BORDER_SIDES = exports.BORDER_WIDTH_TOKENS = exports.RADIUS_TOKENS = exports.STYLE_COLOR_TOKENS = exports.STYLE_SPACING_TOKENS = exports.HOVER_ELEMENTS = exports.BREAKPOINTS = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./define"), exports);
|
|
20
|
+
__exportStar(require("./physical"), exports);
|
|
21
|
+
__exportStar(require("./validate"), exports);
|
|
22
|
+
__exportStar(require("./validator"), exports);
|
|
23
|
+
__exportStar(require("./config"), exports);
|
|
24
|
+
__exportStar(require("./i18n"), exports);
|
|
25
|
+
__exportStar(require("./locales"), exports);
|
|
26
|
+
__exportStar(require("./groups"), exports);
|
|
27
|
+
__exportStar(require("./permissions"), exports);
|
|
28
|
+
__exportStar(require("./pages"), exports);
|
|
29
|
+
__exportStar(require("./actions"), exports);
|
|
30
|
+
__exportStar(require("./composed-block"), exports);
|
|
31
|
+
var style_1 = require("./style");
|
|
32
|
+
Object.defineProperty(exports, "BREAKPOINTS", { enumerable: true, get: function () { return style_1.BREAKPOINTS; } });
|
|
33
|
+
Object.defineProperty(exports, "HOVER_ELEMENTS", { enumerable: true, get: function () { return style_1.HOVER_ELEMENTS; } });
|
|
34
|
+
Object.defineProperty(exports, "STYLE_SPACING_TOKENS", { enumerable: true, get: function () { return style_1.STYLE_SPACING_TOKENS; } });
|
|
35
|
+
Object.defineProperty(exports, "STYLE_COLOR_TOKENS", { enumerable: true, get: function () { return style_1.STYLE_COLOR_TOKENS; } });
|
|
36
|
+
Object.defineProperty(exports, "RADIUS_TOKENS", { enumerable: true, get: function () { return style_1.RADIUS_TOKENS; } });
|
|
37
|
+
Object.defineProperty(exports, "BORDER_WIDTH_TOKENS", { enumerable: true, get: function () { return style_1.BORDER_WIDTH_TOKENS; } });
|
|
38
|
+
Object.defineProperty(exports, "BORDER_SIDES", { enumerable: true, get: function () { return style_1.BORDER_SIDES; } });
|
|
39
|
+
Object.defineProperty(exports, "isLength", { enumerable: true, get: function () { return style_1.isLength; } });
|
|
40
|
+
Object.defineProperty(exports, "isColorValue", { enumerable: true, get: function () { return style_1.isColorValue; } });
|
|
41
|
+
Object.defineProperty(exports, "isTrack", { enumerable: true, get: function () { return style_1.isTrack; } });
|
|
42
|
+
Object.defineProperty(exports, "resolveResponsive", { enumerable: true, get: function () { return style_1.resolveResponsive; } });
|
|
43
|
+
Object.defineProperty(exports, "valueAt", { enumerable: true, get: function () { return style_1.valueAt; } });
|
|
44
|
+
Object.defineProperty(exports, "setAt", { enumerable: true, get: function () { return style_1.setAt; } });
|
|
45
|
+
Object.defineProperty(exports, "validateNodeStyle", { enumerable: true, get: function () { return style_1.validateNodeStyle; } });
|
|
46
|
+
__exportStar(require("./icons"), exports);
|
|
47
|
+
__exportStar(require("./form-controls"), exports);
|
|
48
|
+
__exportStar(require("./theme"), exports);
|
|
49
|
+
__exportStar(require("./search"), exports);
|
|
50
|
+
__exportStar(require("./slug"), exports);
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,6CAA2B;AAC3B,6CAA2B;AAC3B,8CAA4B;AAC5B,2CAAyB;AACzB,yCAAuB;AACvB,4CAA0B;AAC1B,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B;AAC1B,mDAAiC;AACjC,iCAGiB;AAFf,oGAAA,WAAW,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAAE,qGAAA,YAAY,OAAA;AACvH,iGAAA,QAAQ,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAGvF,0CAAwB;AACxB,kDAAgC;AAChC,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Locale } from './i18n';
|
|
2
|
+
export interface LocaleSettings {
|
|
3
|
+
defaultLocale: Locale;
|
|
4
|
+
locales: Locale[];
|
|
5
|
+
}
|
|
6
|
+
/** Returns issue messages; empty when valid. */
|
|
7
|
+
export declare function validateLocaleSettings(s: {
|
|
8
|
+
defaultLocale?: unknown;
|
|
9
|
+
locales?: unknown;
|
|
10
|
+
}): string[];
|
|
11
|
+
export declare function defineLocales(s: LocaleSettings): LocaleSettings;
|
package/dist/locales.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateLocaleSettings = validateLocaleSettings;
|
|
4
|
+
exports.defineLocales = defineLocales;
|
|
5
|
+
const i18n_1 = require("./i18n");
|
|
6
|
+
const HINT = 'use one of en-US, vi-VN, fr-FR, id-ID';
|
|
7
|
+
/** Returns issue messages; empty when valid. */
|
|
8
|
+
function validateLocaleSettings(s) {
|
|
9
|
+
const issues = [];
|
|
10
|
+
const { defaultLocale, locales } = s ?? {};
|
|
11
|
+
if (!Array.isArray(locales) || locales.length === 0) {
|
|
12
|
+
issues.push('locales must be a non-empty list');
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
for (const l of locales) {
|
|
17
|
+
if (!(0, i18n_1.isLocale)(l))
|
|
18
|
+
issues.push(`locale ${JSON.stringify(l)} is not supported (${HINT})`);
|
|
19
|
+
else if (seen.has(l))
|
|
20
|
+
issues.push(`locale "${l}" is listed more than once`);
|
|
21
|
+
seen.add(l);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!(0, i18n_1.isLocale)(defaultLocale)) {
|
|
25
|
+
issues.push(`defaultLocale ${JSON.stringify(defaultLocale)} is not supported (${HINT})`);
|
|
26
|
+
}
|
|
27
|
+
else if (Array.isArray(locales) && locales.length && !locales.includes(defaultLocale)) {
|
|
28
|
+
issues.push(`defaultLocale "${defaultLocale}" must be one of the enabled locales`);
|
|
29
|
+
}
|
|
30
|
+
return issues;
|
|
31
|
+
}
|
|
32
|
+
function defineLocales(s) {
|
|
33
|
+
const issues = validateLocaleSettings(s);
|
|
34
|
+
if (issues.length)
|
|
35
|
+
throw new Error(`Invalid locale settings:\n - ${issues.join('\n - ')}`);
|
|
36
|
+
return s;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sourceRoot":"","sources":["../src/locales.ts"],"names":[],"mappings":";;AAUA,wDAmBC;AAED,sCAIC;AAnCD,iCAA+C;AAO/C,MAAM,IAAI,GAAG,uCAAuC,CAAC;AAErD,gDAAgD;AAChD,SAAgB,sBAAsB,CAAC,CAAiD;IACtF,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,EAAE,a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AK,CAAC,iCAAiC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC7F,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/pages.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** apiId of the core-owned page content type. Projects may not define a type with this id. */
|
|
2
|
+
export declare const PAGE_API_ID = "opencloudcmsPage";
|
|
3
|
+
/** apiIds owned by core: hidden from the Content Type Builder and rejected in project schema files. */
|
|
4
|
+
export declare const CORE_API_IDS: readonly string[];
|
|
5
|
+
export declare const isCoreApiId: (apiId: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* apiIds a project may not use: the core-owned types plus `assets`, whose delivery path `/api/content/assets` is the
|
|
8
|
+
* public asset lookup. Rejected in project schema files and by the Content Type Builder.
|
|
9
|
+
*/
|
|
10
|
+
export declare const RESERVED_API_IDS: readonly string[];
|
|
11
|
+
export declare const isReservedApiId: (apiId: string) => boolean;
|
|
12
|
+
/** First path segments that belong to the CMS itself (compared case-insensitively). */
|
|
13
|
+
export declare const RESERVED_PATH_SEGMENTS: readonly string[];
|
|
14
|
+
export type PagePathResult = {
|
|
15
|
+
ok: true;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
code: 'invalid_path' | 'path_reserved';
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function validatePagePath(path: string): PagePathResult;
|
|
22
|
+
/** 'Giới thiệu' -> '/gioi-thieu'. */
|
|
23
|
+
export declare function slugToPath(title: string): string;
|
|
24
|
+
export type StoredPageContent = {
|
|
25
|
+
format: 'puck';
|
|
26
|
+
formatVersion: number;
|
|
27
|
+
data: {
|
|
28
|
+
root: unknown;
|
|
29
|
+
content: unknown[];
|
|
30
|
+
zones?: Record<string, unknown[]>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Names of the ready-made `coreBlocks` of `@opencloudcms/core/blocks` (kept here, React-free, so the server can
|
|
35
|
+
* tell core blocks from project blocks; a blocks test checks it against `coreBlocks`).
|
|
36
|
+
*/
|
|
37
|
+
export declare const CORE_BLOCK_NAMES: readonly string[];
|
|
38
|
+
/**
|
|
39
|
+
* The blocks a project defines (`blockManifest`). `richText`: prop paths of the block's `b.richText` fields
|
|
40
|
+
* (`'body'`, `'rows[].note'` inside list rows), normalized by the server when a page is saved. `kind`: `layout` or
|
|
41
|
+
* `overlay` for layout and overlay blocks; absent for ordinary blocks (`block`).
|
|
42
|
+
*/
|
|
43
|
+
export type BlockManifest = {
|
|
44
|
+
name: string;
|
|
45
|
+
version: number;
|
|
46
|
+
richText?: string[];
|
|
47
|
+
kind?: 'block' | 'layout' | 'overlay';
|
|
48
|
+
}[];
|
|
49
|
+
/**
|
|
50
|
+
* Block name -> occurrences, over `content`, `zones` and slot fields (arrays of `{ type, props }` among the props
|
|
51
|
+
* of items and of `root.props`). Limitation: without the block registry a slot cannot be told from an ordinary
|
|
52
|
+
* array prop, so a JSON array prop whose elements look like `{ type: string, props: object }` counts as items.
|
|
53
|
+
*/
|
|
54
|
+
export declare function collectBlockNames(c: StoredPageContent | null | undefined): Map<string, number>;
|
|
55
|
+
/**
|
|
56
|
+
* Kinds of page documents: `page` is served at its path; `base` frames pages (never served on its own); `detail` is
|
|
57
|
+
* the template of a content type's entry detail pages (no path of its own; `detailApiId` names the type).
|
|
58
|
+
*/
|
|
59
|
+
export type PageKind = 'page' | 'base' | 'detail';
|
|
60
|
+
export declare const PAGE_KINDS: readonly PageKind[];
|
|
61
|
+
export type RegionMode = 'default' | 'replace' | 'hide';
|
|
62
|
+
export declare const REGION_MODES: readonly RegionMode[];
|
|
63
|
+
/**
|
|
64
|
+
* A page's base choice (page-level, same for every locale). `null`, `{}` or an absent `baseId` = framed by the default
|
|
65
|
+
* base page (its region modes may still be set: `{ regions }`); `baseId: null` = no frame; a document id = that base
|
|
66
|
+
* page. An absent region is `default`.
|
|
67
|
+
*/
|
|
68
|
+
export type PageLayout = {
|
|
69
|
+
baseId?: string | null;
|
|
70
|
+
regions?: Record<string, RegionMode>;
|
|
71
|
+
} | null;
|
|
72
|
+
/** Shape check of a stored `layout` value (whether `baseId` names a base page is checked by the server). */
|
|
73
|
+
export declare function validatePageLayout(value: unknown): {
|
|
74
|
+
ok: true;
|
|
75
|
+
} | {
|
|
76
|
+
ok: false;
|
|
77
|
+
message: string;
|
|
78
|
+
};
|
package/dist/pages.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REGION_MODES = exports.PAGE_KINDS = exports.CORE_BLOCK_NAMES = exports.RESERVED_PATH_SEGMENTS = exports.isReservedApiId = exports.RESERVED_API_IDS = exports.isCoreApiId = exports.CORE_API_IDS = exports.PAGE_API_ID = void 0;
|
|
4
|
+
exports.validatePagePath = validatePagePath;
|
|
5
|
+
exports.slugToPath = slugToPath;
|
|
6
|
+
exports.collectBlockNames = collectBlockNames;
|
|
7
|
+
exports.validatePageLayout = validatePageLayout;
|
|
8
|
+
// Pure, runtime-agnostic page helpers. Must not import from `node:*` (bundled for the browser and shared with Nest).
|
|
9
|
+
const actions_1 = require("./actions");
|
|
10
|
+
/** apiId of the core-owned page content type. Projects may not define a type with this id. */
|
|
11
|
+
exports.PAGE_API_ID = 'opencloudcmsPage';
|
|
12
|
+
/** apiIds owned by core: hidden from the Content Type Builder and rejected in project schema files. */
|
|
13
|
+
exports.CORE_API_IDS = [exports.PAGE_API_ID];
|
|
14
|
+
const isCoreApiId = (apiId) => exports.CORE_API_IDS.includes(apiId);
|
|
15
|
+
exports.isCoreApiId = isCoreApiId;
|
|
16
|
+
/**
|
|
17
|
+
* apiIds a project may not use: the core-owned types plus `assets`, whose delivery path `/api/content/assets` is the
|
|
18
|
+
* public asset lookup. Rejected in project schema files and by the Content Type Builder.
|
|
19
|
+
*/
|
|
20
|
+
exports.RESERVED_API_IDS = [...exports.CORE_API_IDS, 'assets'];
|
|
21
|
+
const isReservedApiId = (apiId) => exports.RESERVED_API_IDS.includes(apiId);
|
|
22
|
+
exports.isReservedApiId = isReservedApiId;
|
|
23
|
+
/** First path segments that belong to the CMS itself (compared case-insensitively). */
|
|
24
|
+
exports.RESERVED_PATH_SEGMENTS = ['admin', 'api', 'oauth2', '__opencloudcms', '_next'];
|
|
25
|
+
const SEGMENT_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
26
|
+
function validatePagePath(path) {
|
|
27
|
+
if (typeof path !== 'string' || !path.startsWith('/')) {
|
|
28
|
+
return { ok: false, code: 'invalid_path', message: 'Path must start with "/"' };
|
|
29
|
+
}
|
|
30
|
+
if (path === '/')
|
|
31
|
+
return { ok: true };
|
|
32
|
+
const segments = path.slice(1).split('/');
|
|
33
|
+
if (exports.RESERVED_PATH_SEGMENTS.includes(segments[0].toLowerCase())) {
|
|
34
|
+
return { ok: false, code: 'path_reserved', message: `Path "/${segments[0]}" is reserved` };
|
|
35
|
+
}
|
|
36
|
+
if (!segments.every((s) => SEGMENT_RE.test(s))) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
code: 'invalid_path',
|
|
40
|
+
message: 'Path segments must be lowercase letters, digits and single hyphens, separated by "/" with no trailing "/"',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return { ok: true };
|
|
44
|
+
}
|
|
45
|
+
/** 'Giới thiệu' -> '/gioi-thieu'. */
|
|
46
|
+
function slugToPath(title) {
|
|
47
|
+
const slug = String(title ?? '')
|
|
48
|
+
.normalize('NFD')
|
|
49
|
+
.replace(/[̀-ͯ]/g, '')
|
|
50
|
+
.replace(/đ/g, 'd')
|
|
51
|
+
.replace(/Đ/g, 'D')
|
|
52
|
+
.toLowerCase()
|
|
53
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
54
|
+
.replace(/^-+|-+$/g, '');
|
|
55
|
+
return slug ? `/${slug}` : '/';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Names of the ready-made `coreBlocks` of `@opencloudcms/core/blocks` (kept here, React-free, so the server can
|
|
59
|
+
* tell core blocks from project blocks; a blocks test checks it against `coreBlocks`).
|
|
60
|
+
*/
|
|
61
|
+
exports.CORE_BLOCK_NAMES = [
|
|
62
|
+
'Section', 'Columns', 'Grid', 'Spacer', 'Divider', 'Heading', 'Text', 'Image', 'Button', 'ButtonGroup',
|
|
63
|
+
'Card', 'Badge', 'Hero', 'FeatureList', 'CallToAction', 'FAQ', 'EntryList',
|
|
64
|
+
];
|
|
65
|
+
function isItem(v) {
|
|
66
|
+
if (!v || typeof v !== 'object')
|
|
67
|
+
return false;
|
|
68
|
+
const o = v;
|
|
69
|
+
return typeof o.type === 'string' && !!o.props && typeof o.props === 'object' && !Array.isArray(o.props);
|
|
70
|
+
}
|
|
71
|
+
const isPlainObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
72
|
+
/**
|
|
73
|
+
* A prop value can hold slot content only as an array. Items in the array are counted (and their own props
|
|
74
|
+
* visited); other plain objects in the array are array-field rows whose values may be slots. A bare object
|
|
75
|
+
* value (not in an array) is plain JSON and is never counted.
|
|
76
|
+
*/
|
|
77
|
+
function visitValue(value, out) {
|
|
78
|
+
if (!Array.isArray(value))
|
|
79
|
+
return;
|
|
80
|
+
for (const el of value) {
|
|
81
|
+
if (isItem(el)) {
|
|
82
|
+
out.set(el.type, (out.get(el.type) ?? 0) + 1);
|
|
83
|
+
for (const v of Object.values(el.props))
|
|
84
|
+
visitValue(v, out);
|
|
85
|
+
}
|
|
86
|
+
else if (isPlainObject(el)) {
|
|
87
|
+
for (const v of Object.values(el))
|
|
88
|
+
visitValue(v, out);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Block name -> occurrences, over `content`, `zones` and slot fields (arrays of `{ type, props }` among the props
|
|
94
|
+
* of items and of `root.props`). Limitation: without the block registry a slot cannot be told from an ordinary
|
|
95
|
+
* array prop, so a JSON array prop whose elements look like `{ type: string, props: object }` counts as items.
|
|
96
|
+
*/
|
|
97
|
+
function collectBlockNames(c) {
|
|
98
|
+
const out = new Map();
|
|
99
|
+
const data = c?.data;
|
|
100
|
+
if (!data)
|
|
101
|
+
return out;
|
|
102
|
+
visitValue(data.content, out);
|
|
103
|
+
for (const zone of Object.values(data.zones ?? {}))
|
|
104
|
+
visitValue(zone, out);
|
|
105
|
+
const rootProps = data.root?.props;
|
|
106
|
+
if (isPlainObject(rootProps))
|
|
107
|
+
for (const v of Object.values(rootProps))
|
|
108
|
+
visitValue(v, out);
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
exports.PAGE_KINDS = ['page', 'base', 'detail'];
|
|
112
|
+
exports.REGION_MODES = ['default', 'replace', 'hide'];
|
|
113
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
114
|
+
/** Shape check of a stored `layout` value (whether `baseId` names a base page is checked by the server). */
|
|
115
|
+
function validatePageLayout(value) {
|
|
116
|
+
if (value == null)
|
|
117
|
+
return { ok: true };
|
|
118
|
+
if (!isPlainObject(value))
|
|
119
|
+
return { ok: false, message: 'layout must be null or an object' };
|
|
120
|
+
const extra = Object.keys(value).filter((k) => k !== 'baseId' && k !== 'regions');
|
|
121
|
+
if (extra.length)
|
|
122
|
+
return { ok: false, message: `layout has unknown keys: ${extra.join(', ')}` };
|
|
123
|
+
// Absent `baseId` = the default base page; when present it is a document id or null (no base page).
|
|
124
|
+
if ('baseId' in value && value.baseId !== null && (typeof value.baseId !== 'string' || !UUID_RE.test(value.baseId))) {
|
|
125
|
+
return { ok: false, message: 'layout.baseId must be a document id or null' };
|
|
126
|
+
}
|
|
127
|
+
if (value.regions !== undefined) {
|
|
128
|
+
if (!isPlainObject(value.regions))
|
|
129
|
+
return { ok: false, message: 'layout.regions must be an object' };
|
|
130
|
+
for (const [name, mode] of Object.entries(value.regions)) {
|
|
131
|
+
if (!actions_1.OVERLAY_NAME_RE.test(name))
|
|
132
|
+
return { ok: false, message: `layout.regions: invalid region name "${name}"` };
|
|
133
|
+
if (!exports.REGION_MODES.includes(mode))
|
|
134
|
+
return { ok: false, message: `layout.regions.${name} must be default, replace or hide` };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { ok: true };
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":";;;AA0BA,4CAiBC;AAGD,gCAUC;AAsDD,8CASC;AAsBD,gDAiBC;AA9JD,qHAAqH;AACrH,uCAA4C;AAE5C,8FAA8F;AACjF,QAAA,WAAW,GAAG,kBAAkB,CAAC;AAE9C,uGAAuG;AAC1F,QAAA,YAAY,GAAsB,CAAC,mBAAW,CAAC,CAAC;AAEtD,MAAM,WAAW,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,oBAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAAvE,QAAA,WAAW,eAA4D;AAEpF;;;GAGG;AACU,QAAA,gBAAgB,GAAsB,CAAC,GAAG,oBAAY,EAAE,QAAQ,CAAC,CAAC;AAExE,MAAM,eAAe,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,wBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAA/E,QAAA,eAAe,mBAAgE;AAE5F,uFAAuF;AAC1E,QAAA,sBAAsB,GAAsB,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAE/G,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAI9C,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAA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C,oBAAY,CAAC,QAAQ,CAAC,IAAkB,CAAC;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,IAAI,mCAAmC,EAAE,CAAC;QAC3I,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed role catalog (spec B §3.1). Groups store a subset of these; a `system` group (Super Admin) always
|
|
3
|
+
* counts as having all of them, including ones added later. Pure: shared by the server and the admin.
|
|
4
|
+
*/
|
|
5
|
+
export declare const PERMISSIONS: readonly ["content.read", "content.create", "content.update", "content.delete", "content.submit", "content.publish", "settings.users", "settings.groups", "settings.content-types", "settings.languages", "customers.read", "customers.manage", "settings.customer-auth", "settings.cors"];
|
|
6
|
+
export type Permission = (typeof PERMISSIONS)[number];
|
|
7
|
+
export declare function isPermission(value: unknown): value is Permission;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERMISSIONS = void 0;
|
|
4
|
+
exports.isPermission = isPermission;
|
|
5
|
+
/**
|
|
6
|
+
* Fixed role catalog (spec B §3.1). Groups store a subset of these; a `system` group (Super Admin) always
|
|
7
|
+
* counts as having all of them, including ones added later. Pure: shared by the server and the admin.
|
|
8
|
+
*/
|
|
9
|
+
exports.PERMISSIONS = [
|
|
10
|
+
'content.read',
|
|
11
|
+
'content.create',
|
|
12
|
+
'content.update',
|
|
13
|
+
'content.delete',
|
|
14
|
+
'content.submit',
|
|
15
|
+
'content.publish',
|
|
16
|
+
'settings.users',
|
|
17
|
+
'settings.groups',
|
|
18
|
+
'settings.content-types',
|
|
19
|
+
'settings.languages',
|
|
20
|
+
'customers.read',
|
|
21
|
+
'customers.manage',
|
|
22
|
+
'settings.customer-auth',
|
|
23
|
+
'settings.cors',
|
|
24
|
+
];
|
|
25
|
+
const KNOWN = new Set(exports.PERMISSIONS);
|
|
26
|
+
function isPermission(value) {
|
|
27
|
+
return typeof value === 'string' && KNOWN.has(value);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":";;;AAyBA,oCAEC;AA3BD;;;GAGG;AACU,QAAA,WAAW,GAAG;IACzB,cAAc;IACd,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,iBAAiB;IACjB,wBAAwB;IACxB,oBAAoB;IACpB,gBAAgB;IAChB,kBAAkB;IAClB,wBAAwB;IACxB,eAAe;CACP,CAAC;AAIX,MAAM,KAAK,GAAwB,IAAI,GAAG,CAAC,mBAAW,CAAC,CAAC;AAExD,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Physical storage mapping: how a content type becomes Postgres tables.
|
|
3
|
+
*
|
|
4
|
+
* ct_<api_id> one row per (document, status) with shared fields
|
|
5
|
+
* ct_<api_id>_l10n one row per (entry, locale) with localizable fields
|
|
6
|
+
* ct_<api_id>__rel__<field> join table for every multiple relation field
|
|
7
|
+
*
|
|
8
|
+
* Both the migration generator and the runtime repository use these helpers,
|
|
9
|
+
* so the two can never disagree about table or column names.
|
|
10
|
+
*/
|
|
11
|
+
import type { ContentTypeDefinition, FieldDefinition } from './types';
|
|
12
|
+
export declare const SYSTEM_TABLES: {
|
|
13
|
+
readonly assets: "opencms_assets";
|
|
14
|
+
readonly assetFolders: "opencms_asset_folders";
|
|
15
|
+
readonly taxonomies: "opencms_taxonomies";
|
|
16
|
+
readonly taxonomyTerms: "opencms_taxonomy_terms";
|
|
17
|
+
readonly entryVersions: "opencms_entry_versions";
|
|
18
|
+
readonly workflow: "opencms_workflow";
|
|
19
|
+
};
|
|
20
|
+
export declare const PG_MAX_IDENTIFIER = 63;
|
|
21
|
+
export declare function snake(input: string): string;
|
|
22
|
+
/** Keeps identifiers within Postgres' 63 byte limit, deterministically. */
|
|
23
|
+
export declare function pgName(name: string): string;
|
|
24
|
+
export declare const mainTable: (def: Pick<ContentTypeDefinition, "apiId">) => string;
|
|
25
|
+
export declare const l10nTable: (def: Pick<ContentTypeDefinition, "apiId">) => string;
|
|
26
|
+
export declare const relTable: (def: Pick<ContentTypeDefinition, "apiId">, field: Pick<FieldDefinition, "name">) => string;
|
|
27
|
+
export interface PhysicalColumn {
|
|
28
|
+
name: string;
|
|
29
|
+
/** Postgres type, e.g. `varchar(255)`. */
|
|
30
|
+
type: string;
|
|
31
|
+
notNull?: boolean;
|
|
32
|
+
defaultSql?: string;
|
|
33
|
+
references?: {
|
|
34
|
+
table: string;
|
|
35
|
+
column: string;
|
|
36
|
+
onDelete: 'cascade' | 'set null';
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type FieldStorage = {
|
|
40
|
+
mode: 'columns';
|
|
41
|
+
location: 'main' | 'l10n';
|
|
42
|
+
table: string;
|
|
43
|
+
columns: PhysicalColumn[];
|
|
44
|
+
} | {
|
|
45
|
+
mode: 'relation';
|
|
46
|
+
table: string;
|
|
47
|
+
targetTable: string | null;
|
|
48
|
+
};
|
|
49
|
+
export declare function isMultiRelation(field: FieldDefinition): boolean;
|
|
50
|
+
/** Postgres column(s) for a scalar / single relation field. */
|
|
51
|
+
export declare function fieldColumns(field: FieldDefinition): PhysicalColumn[];
|
|
52
|
+
export declare function fieldStorage(def: ContentTypeDefinition, field: FieldDefinition): FieldStorage;
|
|
53
|
+
export declare function mainBaseColumns(): PhysicalColumn[];
|
|
54
|
+
export declare function l10nBaseColumns(def: ContentTypeDefinition): PhysicalColumn[];
|
|
55
|
+
export declare function relBaseColumns(def: ContentTypeDefinition, field: FieldDefinition): PhysicalColumn[];
|
|
56
|
+
export interface IndexSpec {
|
|
57
|
+
name: string;
|
|
58
|
+
table: string;
|
|
59
|
+
columns: string[];
|
|
60
|
+
unique: boolean;
|
|
61
|
+
}
|
|
62
|
+
export declare const mainPkeyName: (def: ContentTypeDefinition) => string;
|
|
63
|
+
export declare const l10nPkeyName: (def: ContentTypeDefinition) => string;
|
|
64
|
+
export declare const relPkeyName: (def: ContentTypeDefinition, field: FieldDefinition) => string;
|
|
65
|
+
export declare const relTargetIndexName: (def: ContentTypeDefinition, field: FieldDefinition) => string;
|
|
66
|
+
export declare const documentStatusIndexName: (def: ContentTypeDefinition) => string;
|
|
67
|
+
/** Index created for an `indexed` / `unique` field, or null. */
|
|
68
|
+
export declare function fieldIndex(def: ContentTypeDefinition, field: FieldDefinition): IndexSpec | null;
|
|
69
|
+
/** Every index (including primary keys) that belongs to a content type. Used for renames. */
|
|
70
|
+
export declare function typeIndexNames(def: ContentTypeDefinition): string[];
|
|
71
|
+
/** Every table that belongs to a content type. */
|
|
72
|
+
export declare function typeTableNames(def: ContentTypeDefinition): string[];
|