@kodacms/shared 0.0.0-stage → 0.1.2

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 ADDED
@@ -0,0 +1,17 @@
1
+ # @kodacms/shared
2
+
3
+ ## 0.1.2
4
+
5
+ No changes in this release.
6
+
7
+ ## 0.1.1
8
+
9
+ ### Patch Changes
10
+
11
+ - Пакеты KodaCMS публикуются в публичном npm (`registry.npmjs.org`): `npx create-kodacms my-site` (или `bunx create-kodacms my-site`) и `npm install @kodacms/core` работают без токенов и `.npmrc`. Приватный реестр GitLab (`create-kodacms --registry <url>`) по-прежнему поддерживается. README пакетов описывают установку из npm; код пакетов не менялся. (0ab4d17)
12
+
13
+ ## 0.1.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Первая версия пакетов KodaCMS: ядро `@kodacms/core` (NestJS: коллекции и globals из конфига, REST и Local API, вход, роли, аудит, медиа, две ветки миграций), админка `@kodacms/admin` (готовая сборка и свои компоненты проекта), консольные команды `@kodacms/cli` (`koda dev`, `build`, `migrate`, `migration`, `create-admin`…), контракт `@kodacms/shared` и `create-kodacms` с шаблонами `blank` и `website`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KodaCMS contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # `@kodacms/shared` (`packages/shared`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Контракт сервера, CLI и админки: вычислитель условий `admin-condition.ts`, манифест своих компонентов `admin-manifest.ts`, иконки страниц `admin-view-icons.ts`, раскладка проекта `project-layout.ts` (`PROJECT_LAYOUT` — пути от корня проекта). Пакет импортируют и ядро (`@kodacms/core`), и админка (`@kodacms/admin`): `import { … } from '@kodacms/shared'`.
4
+
5
+ Правило: никаких зависимостей и импортов — ни Nest, ни Vue, ни zod, ни `node:*`, ни других пакетов. Только чистый TypeScript; файлы пакета импортируют друг друга относительными путями с `.js`, публичное — через `index.ts`.
6
+
7
+ ## Установка
8
+
9
+ Ставить отдельно не нужно: `@kodacms/shared` — зависимость `@kodacms/core` и `@kodacms/admin` той же версии (все пакеты `@kodacms/*` выходят одной версией). Зависимостей и peer-зависимостей нет; ESM, Node.js 24.
10
+
11
+ Изменения — `CHANGELOG.md` пакета.
@@ -0,0 +1,25 @@
1
+ export declare const CONDITION_OPERATORS: readonly ["equals", "not_equals", "in", "not_in", "exists", "greater_than", "greater_than_equal", "less_than", "less_than_equal"];
2
+ export type ConditionOperator = (typeof CONDITION_OPERATORS)[number];
3
+ export type ConditionValue = string | number | boolean | null;
4
+ export interface ConditionOperators {
5
+ equals?: ConditionValue;
6
+ not_equals?: ConditionValue;
7
+ in?: readonly ConditionValue[];
8
+ not_in?: readonly ConditionValue[];
9
+ exists?: boolean;
10
+ greater_than?: ConditionValue;
11
+ greater_than_equal?: ConditionValue;
12
+ less_than?: ConditionValue;
13
+ less_than_equal?: ConditionValue;
14
+ }
15
+ export interface Condition {
16
+ and?: readonly Condition[];
17
+ or?: readonly Condition[];
18
+ [path: string]: ConditionOperators | readonly Condition[] | undefined;
19
+ }
20
+ type Data = Readonly<Record<string, unknown>>;
21
+ export declare function conditionValueAt(data: Data, path: string): unknown;
22
+ export declare function evaluateCondition(condition: Condition, data: Data): boolean;
23
+ export declare function conditionPaths(condition: Condition): string[];
24
+ export declare function sameCondition(a: Condition, b: Condition): boolean;
25
+ export {};
@@ -0,0 +1,177 @@
1
+ export const CONDITION_OPERATORS = [
2
+ 'equals',
3
+ 'not_equals',
4
+ 'in',
5
+ 'not_in',
6
+ 'exists',
7
+ 'greater_than',
8
+ 'greater_than_equal',
9
+ 'less_than',
10
+ 'less_than_equal',
11
+ ];
12
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
13
+ export function conditionValueAt(data, path) {
14
+ let current = data;
15
+ for (const key of path.split('.')) {
16
+ if (!isRecord(current))
17
+ return undefined;
18
+ current = current[key];
19
+ }
20
+ return Array.isArray(current) ? current.map(toId) : toId(current);
21
+ }
22
+ function toId(value) {
23
+ if (value instanceof Date)
24
+ return value.toISOString();
25
+ if (!isRecord(value))
26
+ return value;
27
+ if ('relationTo' in value && 'value' in value)
28
+ return toId(value.value);
29
+ if ('id' in value)
30
+ return value.id;
31
+ return value;
32
+ }
33
+ const isEmpty = (value) => value === null ||
34
+ value === undefined ||
35
+ value === '' ||
36
+ (Array.isArray(value) && value.length === 0);
37
+ function same(a, b) {
38
+ if (b === null)
39
+ return isEmpty(a);
40
+ if (isEmpty(a))
41
+ return false;
42
+ if (a === b)
43
+ return true;
44
+ if (typeof b === 'number' && typeof a === 'string')
45
+ return Number(a) === b;
46
+ if (typeof a === 'number' && typeof b === 'string')
47
+ return a === Number(b);
48
+ if (typeof a === 'string' && typeof b === 'string') {
49
+ const ta = dateTime(a);
50
+ const tb = dateTime(b);
51
+ return ta !== undefined && ta === tb;
52
+ }
53
+ return false;
54
+ }
55
+ function matches(value, target) {
56
+ if (Array.isArray(value)) {
57
+ return target === null
58
+ ? value.length === 0
59
+ : value.some((item) => same(item, target));
60
+ }
61
+ return same(value, target);
62
+ }
63
+ const DATE_LIKE = /^\d{4}-\d{2}-\d{2}/;
64
+ function dateTime(value) {
65
+ if (!DATE_LIKE.test(value))
66
+ return undefined;
67
+ const time = Date.parse(value);
68
+ return Number.isNaN(time) ? undefined : time;
69
+ }
70
+ function compare(a, b) {
71
+ if (isEmpty(a) || b === null || Array.isArray(a))
72
+ return undefined;
73
+ const na = typeof a === 'number' ? a : typeof a === 'string' ? toNumber(a) : undefined;
74
+ const nb = typeof b === 'number' ? b : typeof b === 'string' ? toNumber(b) : undefined;
75
+ if (na !== undefined && nb !== undefined)
76
+ return Math.sign(na - nb);
77
+ if (typeof a === 'string' && typeof b === 'string') {
78
+ const ta = dateTime(a);
79
+ const tb = dateTime(b);
80
+ if (ta !== undefined && tb !== undefined)
81
+ return Math.sign(ta - tb);
82
+ return a < b ? -1 : a > b ? 1 : 0;
83
+ }
84
+ return undefined;
85
+ }
86
+ function toNumber(value) {
87
+ if (value.trim() === '' || DATE_LIKE.test(value))
88
+ return undefined;
89
+ const number = Number(value);
90
+ return Number.isFinite(number) ? number : undefined;
91
+ }
92
+ function checkOperator(value, operator, operand) {
93
+ switch (operator) {
94
+ case 'equals':
95
+ return matches(value, operand);
96
+ case 'not_equals':
97
+ return !matches(value, operand);
98
+ case 'in':
99
+ return (Array.isArray(operand) &&
100
+ operand.some((item) => matches(value, item)));
101
+ case 'not_in':
102
+ return (Array.isArray(operand) &&
103
+ !operand.some((item) => matches(value, item)));
104
+ case 'exists':
105
+ return operand === !isEmpty(value);
106
+ case 'greater_than':
107
+ case 'greater_than_equal':
108
+ case 'less_than':
109
+ case 'less_than_equal': {
110
+ const order = compare(value, operand);
111
+ if (order === undefined)
112
+ return false;
113
+ if (operator === 'greater_than')
114
+ return order > 0;
115
+ if (operator === 'greater_than_equal')
116
+ return order >= 0;
117
+ if (operator === 'less_than')
118
+ return order < 0;
119
+ return order <= 0;
120
+ }
121
+ default:
122
+ return false;
123
+ }
124
+ }
125
+ export function evaluateCondition(condition, data) {
126
+ for (const [key, entry] of Object.entries(condition)) {
127
+ if (entry === undefined)
128
+ continue;
129
+ if (key === 'and' || key === 'or') {
130
+ const list = Array.isArray(entry) ? entry : [];
131
+ const ok = key === 'and'
132
+ ? list.every((child) => evaluateCondition(child, data))
133
+ : list.some((child) => evaluateCondition(child, data));
134
+ if (!ok)
135
+ return false;
136
+ continue;
137
+ }
138
+ if (!isRecord(entry))
139
+ return false;
140
+ const value = conditionValueAt(data, key);
141
+ for (const [operator, operand] of Object.entries(entry)) {
142
+ if (operand === undefined)
143
+ continue;
144
+ if (!checkOperator(value, operator, operand))
145
+ return false;
146
+ }
147
+ }
148
+ return true;
149
+ }
150
+ export function conditionPaths(condition) {
151
+ return Object.entries(condition).flatMap(([key, entry]) => {
152
+ if (entry === undefined)
153
+ return [];
154
+ if (key === 'and' || key === 'or') {
155
+ return Array.isArray(entry)
156
+ ? entry.flatMap(conditionPaths)
157
+ : [];
158
+ }
159
+ return [key];
160
+ });
161
+ }
162
+ export function sameCondition(a, b) {
163
+ return canonical(a) === canonical(b);
164
+ }
165
+ function canonical(value) {
166
+ if (Array.isArray(value))
167
+ return `[${value.map(canonical).join(',')}]`;
168
+ if (isRecord(value)) {
169
+ return `{${Object.keys(value)
170
+ .filter((key) => value[key] !== undefined)
171
+ .sort()
172
+ .map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`)
173
+ .join(',')}}`;
174
+ }
175
+ return JSON.stringify(value);
176
+ }
177
+ //# sourceMappingURL=admin-condition.js.map
@@ -0,0 +1,10 @@
1
+ export declare const ADMIN_COMPONENT_NAME_PATTERN: RegExp;
2
+ export declare function isAdminComponentName(name: string): boolean;
3
+ export declare const ADMIN_COMPONENTS_MANIFEST = "koda-components.json";
4
+ export declare const ADMIN_COMPONENTS_MANIFEST_VERSION = 1;
5
+ export interface AdminComponentsManifest {
6
+ version: typeof ADMIN_COMPONENTS_MANIFEST_VERSION;
7
+ components: string[];
8
+ }
9
+ export declare function createAdminComponentsManifest(names: Iterable<string>): AdminComponentsManifest;
10
+ export declare function parseAdminComponentsManifest(text: string): string[] | null;
@@ -0,0 +1,32 @@
1
+ export const ADMIN_COMPONENT_NAME_PATTERN = /^[a-z0-9-]+(\/[A-Za-z0-9-]+)*$/;
2
+ export function isAdminComponentName(name) {
3
+ return ADMIN_COMPONENT_NAME_PATTERN.test(name);
4
+ }
5
+ export const ADMIN_COMPONENTS_MANIFEST = 'koda-components.json';
6
+ export const ADMIN_COMPONENTS_MANIFEST_VERSION = 1;
7
+ export function createAdminComponentsManifest(names) {
8
+ return {
9
+ version: ADMIN_COMPONENTS_MANIFEST_VERSION,
10
+ components: [...new Set(names)].sort(),
11
+ };
12
+ }
13
+ export function parseAdminComponentsManifest(text) {
14
+ let data;
15
+ try {
16
+ data = JSON.parse(text);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ if (typeof data !== 'object' || data === null)
22
+ return null;
23
+ const { version, components } = data;
24
+ if (version !== ADMIN_COMPONENTS_MANIFEST_VERSION)
25
+ return null;
26
+ if (!Array.isArray(components) ||
27
+ !components.every((name) => typeof name === 'string')) {
28
+ return null;
29
+ }
30
+ return components;
31
+ }
32
+ //# sourceMappingURL=admin-manifest.js.map
@@ -0,0 +1,2 @@
1
+ export declare const ADMIN_VIEW_ICONS: readonly ["activity", "archive", "bell", "book-open", "bookmark", "box", "calendar", "chart-bar", "chart-column", "chart-line", "chart-pie", "clipboard-list", "clock", "credit-card", "database", "file-text", "files", "folder", "globe", "heart", "image", "inbox", "layers", "layout-dashboard", "link", "list-checks", "mail", "map-pin", "megaphone", "message-square", "newspaper", "package", "search", "settings", "shield", "shopping-cart", "sparkles", "star", "table", "tag", "trending-up", "truck", "user", "users", "wallet", "wrench"];
2
+ export type AdminViewIcon = (typeof ADMIN_VIEW_ICONS)[number];
@@ -0,0 +1,49 @@
1
+ export const ADMIN_VIEW_ICONS = [
2
+ 'activity',
3
+ 'archive',
4
+ 'bell',
5
+ 'book-open',
6
+ 'bookmark',
7
+ 'box',
8
+ 'calendar',
9
+ 'chart-bar',
10
+ 'chart-column',
11
+ 'chart-line',
12
+ 'chart-pie',
13
+ 'clipboard-list',
14
+ 'clock',
15
+ 'credit-card',
16
+ 'database',
17
+ 'file-text',
18
+ 'files',
19
+ 'folder',
20
+ 'globe',
21
+ 'heart',
22
+ 'image',
23
+ 'inbox',
24
+ 'layers',
25
+ 'layout-dashboard',
26
+ 'link',
27
+ 'list-checks',
28
+ 'mail',
29
+ 'map-pin',
30
+ 'megaphone',
31
+ 'message-square',
32
+ 'newspaper',
33
+ 'package',
34
+ 'search',
35
+ 'settings',
36
+ 'shield',
37
+ 'shopping-cart',
38
+ 'sparkles',
39
+ 'star',
40
+ 'table',
41
+ 'tag',
42
+ 'trending-up',
43
+ 'truck',
44
+ 'user',
45
+ 'users',
46
+ 'wallet',
47
+ 'wrench',
48
+ ];
49
+ //# sourceMappingURL=admin-view-icons.js.map
@@ -0,0 +1,4 @@
1
+ export { CONDITION_OPERATORS, conditionPaths, conditionValueAt, evaluateCondition, sameCondition, type Condition, type ConditionOperator, type ConditionOperators, type ConditionValue, } from './admin-condition.js';
2
+ export { ADMIN_COMPONENT_NAME_PATTERN, ADMIN_COMPONENTS_MANIFEST, ADMIN_COMPONENTS_MANIFEST_VERSION, createAdminComponentsManifest, isAdminComponentName, parseAdminComponentsManifest, type AdminComponentsManifest, } from './admin-manifest.js';
3
+ export { ADMIN_VIEW_ICONS, type AdminViewIcon } from './admin-view-icons.js';
4
+ export { PROJECT_LAYOUT } from './project-layout.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { CONDITION_OPERATORS, conditionPaths, conditionValueAt, evaluateCondition, sameCondition, } from './admin-condition.js';
2
+ export { ADMIN_COMPONENT_NAME_PATTERN, ADMIN_COMPONENTS_MANIFEST, ADMIN_COMPONENTS_MANIFEST_VERSION, createAdminComponentsManifest, isAdminComponentName, parseAdminComponentsManifest, } from './admin-manifest.js';
3
+ export { ADMIN_VIEW_ICONS } from './admin-view-icons.js';
4
+ export { PROJECT_LAYOUT } from './project-layout.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ export declare const PROJECT_LAYOUT: {
2
+ readonly sourceDir: "src";
3
+ readonly config: "src/kodacms.config.ts";
4
+ readonly generatedDir: "src/database/schema/generated";
5
+ readonly schema: "src/database/schema/generated/index.ts";
6
+ readonly migrationsDir: "drizzle";
7
+ readonly adminComponentsDir: "src/admin/components";
8
+ readonly adminGeneratedDir: "src/admin/generated";
9
+ readonly adminDistDir: "admin/dist";
10
+ readonly buildTsconfig: "tsconfig.build.json";
11
+ readonly buildConfig: "dist/kodacms.config.js";
12
+ };
@@ -0,0 +1,13 @@
1
+ export const PROJECT_LAYOUT = {
2
+ sourceDir: 'src',
3
+ config: 'src/kodacms.config.ts',
4
+ generatedDir: 'src/database/schema/generated',
5
+ schema: 'src/database/schema/generated/index.ts',
6
+ migrationsDir: 'drizzle',
7
+ adminComponentsDir: 'src/admin/components',
8
+ adminGeneratedDir: 'src/admin/generated',
9
+ adminDistDir: 'admin/dist',
10
+ buildTsconfig: 'tsconfig.build.json',
11
+ buildConfig: 'dist/kodacms.config.js',
12
+ };
13
+ //# sourceMappingURL=project-layout.js.map
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@kodacms/shared",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "KodaCMS: контракт сервера и админки (условия, манифест своих компонентов, иконки, раскладка проекта)",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "@kodacms/source": "./src/index.ts",
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "CHANGELOG.md",
18
+ "dist",
19
+ "!dist/**/*.tsbuildinfo",
20
+ "!dist/**/*.map"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc -b tsconfig.build.json",
24
+ "test": "vitest run"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^26.6.11",
28
+ "typescript": "^6.0.3",
29
+ "vitest": "^5.1.2"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }