@notty/types 0.2.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/dist/index.cjs +85 -0
- package/dist/index.d.cts +224 -0
- package/dist/index.d.mts +224 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +57 -0
- package/dist/index.mjs +57 -0
- package/package.json +34 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SchemaValidationError: () => SchemaValidationError,
|
|
24
|
+
exampleSchema: () => exampleSchema
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/acms-schema.ts
|
|
29
|
+
var exampleSchema = {
|
|
30
|
+
kind: "collectionType",
|
|
31
|
+
info: {
|
|
32
|
+
singularName: "article",
|
|
33
|
+
pluralName: "articles",
|
|
34
|
+
displayName: "Article",
|
|
35
|
+
description: "Blog articles"
|
|
36
|
+
},
|
|
37
|
+
options: {
|
|
38
|
+
draftAndPublish: true,
|
|
39
|
+
timestamps: true
|
|
40
|
+
},
|
|
41
|
+
attributes: {
|
|
42
|
+
title: {
|
|
43
|
+
type: "string",
|
|
44
|
+
required: true,
|
|
45
|
+
maxLength: 255
|
|
46
|
+
},
|
|
47
|
+
slug: {
|
|
48
|
+
type: "string",
|
|
49
|
+
required: true,
|
|
50
|
+
unique: true,
|
|
51
|
+
maxLength: 255
|
|
52
|
+
},
|
|
53
|
+
content: {
|
|
54
|
+
type: "richtext",
|
|
55
|
+
required: true
|
|
56
|
+
},
|
|
57
|
+
publishedAt: {
|
|
58
|
+
type: "datetime"
|
|
59
|
+
},
|
|
60
|
+
author: {
|
|
61
|
+
type: "relation",
|
|
62
|
+
relation: "manyToOne",
|
|
63
|
+
target: "users"
|
|
64
|
+
},
|
|
65
|
+
categories: {
|
|
66
|
+
type: "relation",
|
|
67
|
+
relation: "manyToMany",
|
|
68
|
+
target: "categories"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/validation.ts
|
|
74
|
+
var SchemaValidationError = class extends Error {
|
|
75
|
+
constructor(result, message) {
|
|
76
|
+
super(message || "Schema validation failed");
|
|
77
|
+
this.result = result;
|
|
78
|
+
this.name = "SchemaValidationError";
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
SchemaValidationError,
|
|
84
|
+
exampleSchema
|
|
85
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Types
|
|
3
|
+
*/
|
|
4
|
+
interface ContentEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
publishedAt?: Date;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface QueryOptions {
|
|
12
|
+
filters?: Record<string, unknown>;
|
|
13
|
+
sort?: string[];
|
|
14
|
+
pagination?: {
|
|
15
|
+
page: number;
|
|
16
|
+
pageSize: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* User Types
|
|
22
|
+
*/
|
|
23
|
+
interface User {
|
|
24
|
+
id: string;
|
|
25
|
+
email: string;
|
|
26
|
+
username: string;
|
|
27
|
+
role: 'admin' | 'editor' | 'viewer';
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Plugin Types
|
|
34
|
+
*/
|
|
35
|
+
interface Plugin {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
config?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
interface PluginHooks {
|
|
42
|
+
beforeCreate?: (data: unknown) => Promise<unknown>;
|
|
43
|
+
afterCreate?: (data: unknown) => Promise<void>;
|
|
44
|
+
beforeUpdate?: (id: string, data: unknown) => Promise<unknown>;
|
|
45
|
+
afterUpdate?: (id: string, data: unknown) => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Theme Types
|
|
50
|
+
*/
|
|
51
|
+
interface Theme {
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
description: string;
|
|
55
|
+
author: string;
|
|
56
|
+
templates: string[];
|
|
57
|
+
}
|
|
58
|
+
interface ThemeConfig {
|
|
59
|
+
colors?: Record<string, string>;
|
|
60
|
+
fonts?: Record<string, string>;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* ACms Universal Schema Format
|
|
66
|
+
* Аналог Strapi schema, но адаптированный для Drizzle
|
|
67
|
+
*/
|
|
68
|
+
type FieldType = 'string' | 'text' | 'richtext' | 'integer' | 'bigint' | 'decimal' | 'boolean' | 'date' | 'datetime' | 'json' | 'enum' | 'relation' | 'component' | 'media';
|
|
69
|
+
interface ACmsField {
|
|
70
|
+
type: FieldType;
|
|
71
|
+
required?: boolean;
|
|
72
|
+
unique?: boolean;
|
|
73
|
+
default?: unknown;
|
|
74
|
+
minLength?: number;
|
|
75
|
+
maxLength?: number;
|
|
76
|
+
min?: number;
|
|
77
|
+
max?: number;
|
|
78
|
+
enum?: string[];
|
|
79
|
+
target?: string;
|
|
80
|
+
relation?: 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany';
|
|
81
|
+
mappedBy?: string;
|
|
82
|
+
inversedBy?: string;
|
|
83
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT';
|
|
84
|
+
component?: string;
|
|
85
|
+
repeatable?: boolean;
|
|
86
|
+
index?: boolean | 'unique' | 'fulltext';
|
|
87
|
+
foreignKey?: {
|
|
88
|
+
table: string;
|
|
89
|
+
field: string;
|
|
90
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
91
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
interface ACmsSchema {
|
|
95
|
+
kind: 'collectionType' | 'singleType';
|
|
96
|
+
info: {
|
|
97
|
+
singularName: string;
|
|
98
|
+
pluralName: string;
|
|
99
|
+
displayName: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
};
|
|
102
|
+
options?: {
|
|
103
|
+
draftAndPublish?: boolean;
|
|
104
|
+
timestamps?: boolean;
|
|
105
|
+
softDelete?: boolean;
|
|
106
|
+
};
|
|
107
|
+
attributes: Record<string, ACmsField>;
|
|
108
|
+
indexes?: Array<{
|
|
109
|
+
fields: string[];
|
|
110
|
+
type: 'index' | 'unique' | 'fulltext';
|
|
111
|
+
name?: string;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Пример схемы в универсальном формате
|
|
116
|
+
*/
|
|
117
|
+
declare const exampleSchema: ACmsSchema;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Validation types for ACms Schema
|
|
121
|
+
*/
|
|
122
|
+
interface ValidationError {
|
|
123
|
+
field: string;
|
|
124
|
+
message: string;
|
|
125
|
+
code: ValidationErrorCode;
|
|
126
|
+
details?: unknown;
|
|
127
|
+
}
|
|
128
|
+
type ValidationErrorCode = 'MISSING_REQUIRED_FIELD' | 'INVALID_FIELD_TYPE' | 'INVALID_RELATION_TYPE' | 'DUPLICATE_FIELD_NAME' | 'INVALID_CONSTRAINT' | 'INVALID_ENUM_VALUES' | 'INVALID_RELATION_TARGET' | 'INVALID_RELATION_INVERSE' | 'MISSING_INFO' | 'EMPTY_ATTRIBUTES' | 'INVALID_MIN_MAX' | 'INVALID_LENGTH_CONSTRAINT' | 'INVALID_INDEX_TYPE' | 'INVALID_FOREIGN_KEY' | 'INVALID_INDEX_FIELDS';
|
|
129
|
+
interface ValidationResult {
|
|
130
|
+
valid: boolean;
|
|
131
|
+
errors: ValidationError[];
|
|
132
|
+
}
|
|
133
|
+
declare class SchemaValidationError extends Error {
|
|
134
|
+
result: ValidationResult;
|
|
135
|
+
constructor(result: ValidationResult, message?: string);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Migration types for ACms Database
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* Database connection for migrations
|
|
143
|
+
* Union type supporting SQLite, PostgreSQL, and MySQL
|
|
144
|
+
*/
|
|
145
|
+
type MigrationDatabaseConnection = SQLiteMigrationConnection | PostgresMigrationConnection | MySQLMigrationConnection;
|
|
146
|
+
/**
|
|
147
|
+
* SQLite database connection for migrations
|
|
148
|
+
*/
|
|
149
|
+
interface SQLiteMigrationConnection {
|
|
150
|
+
exec(sql: string): void;
|
|
151
|
+
prepare(sql: string): {
|
|
152
|
+
run(...params: unknown[]): void;
|
|
153
|
+
all(...params: unknown[]): unknown[];
|
|
154
|
+
get(...params: unknown[]): unknown;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* PostgreSQL database connection for migrations
|
|
159
|
+
*/
|
|
160
|
+
interface PostgresMigrationConnection {
|
|
161
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
162
|
+
rows?: unknown[];
|
|
163
|
+
rowCount?: number;
|
|
164
|
+
}>;
|
|
165
|
+
query(sql: string, params?: unknown[]): Promise<{
|
|
166
|
+
rows: unknown[];
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* MySQL database connection for migrations
|
|
171
|
+
*/
|
|
172
|
+
interface MySQLMigrationConnection {
|
|
173
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
174
|
+
rows?: unknown[];
|
|
175
|
+
insertId?: number;
|
|
176
|
+
affectedRows?: number;
|
|
177
|
+
}>;
|
|
178
|
+
query(sql: string, params?: unknown[]): Promise<unknown[]>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Migration interface - структура файла миграции
|
|
182
|
+
*/
|
|
183
|
+
interface Migration {
|
|
184
|
+
up: (db: MigrationDatabaseConnection) => Promise<void>;
|
|
185
|
+
down: (db: MigrationDatabaseConnection) => Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Migration record - запись в таблице _migrations
|
|
189
|
+
*/
|
|
190
|
+
interface MigrationRecord {
|
|
191
|
+
id: number;
|
|
192
|
+
name: string;
|
|
193
|
+
timestamp: string;
|
|
194
|
+
batch: number;
|
|
195
|
+
executedAt: Date;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Migration status - статус отдельной миграции
|
|
199
|
+
*/
|
|
200
|
+
interface MigrationStatus {
|
|
201
|
+
name: string;
|
|
202
|
+
timestamp: string;
|
|
203
|
+
status: 'pending' | 'executed';
|
|
204
|
+
batch?: number;
|
|
205
|
+
executedAt?: Date;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Migration result - результат выполнения миграции
|
|
209
|
+
*/
|
|
210
|
+
interface MigrationResult {
|
|
211
|
+
success: boolean;
|
|
212
|
+
migrationsRun: string[];
|
|
213
|
+
errors?: string[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Rollback result - результат отката миграций
|
|
217
|
+
*/
|
|
218
|
+
interface RollbackResult {
|
|
219
|
+
success: boolean;
|
|
220
|
+
migrationsRolledBack: string[];
|
|
221
|
+
errors?: string[];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { type ACmsField, type ACmsSchema, type ContentEntry, type FieldType, type Migration, type MigrationDatabaseConnection, type MigrationRecord, type MigrationResult, type MigrationStatus, type MySQLMigrationConnection, type Plugin, type PluginHooks, type PostgresMigrationConnection, type QueryOptions, type RollbackResult, type SQLiteMigrationConnection, SchemaValidationError, type Theme, type ThemeConfig, type User, type ValidationError, type ValidationErrorCode, type ValidationResult, exampleSchema };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Types
|
|
3
|
+
*/
|
|
4
|
+
interface ContentEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
publishedAt?: Date;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface QueryOptions {
|
|
12
|
+
filters?: Record<string, unknown>;
|
|
13
|
+
sort?: string[];
|
|
14
|
+
pagination?: {
|
|
15
|
+
page: number;
|
|
16
|
+
pageSize: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* User Types
|
|
22
|
+
*/
|
|
23
|
+
interface User {
|
|
24
|
+
id: string;
|
|
25
|
+
email: string;
|
|
26
|
+
username: string;
|
|
27
|
+
role: 'admin' | 'editor' | 'viewer';
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Plugin Types
|
|
34
|
+
*/
|
|
35
|
+
interface Plugin {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
config?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
interface PluginHooks {
|
|
42
|
+
beforeCreate?: (data: unknown) => Promise<unknown>;
|
|
43
|
+
afterCreate?: (data: unknown) => Promise<void>;
|
|
44
|
+
beforeUpdate?: (id: string, data: unknown) => Promise<unknown>;
|
|
45
|
+
afterUpdate?: (id: string, data: unknown) => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Theme Types
|
|
50
|
+
*/
|
|
51
|
+
interface Theme {
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
description: string;
|
|
55
|
+
author: string;
|
|
56
|
+
templates: string[];
|
|
57
|
+
}
|
|
58
|
+
interface ThemeConfig {
|
|
59
|
+
colors?: Record<string, string>;
|
|
60
|
+
fonts?: Record<string, string>;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* ACms Universal Schema Format
|
|
66
|
+
* Аналог Strapi schema, но адаптированный для Drizzle
|
|
67
|
+
*/
|
|
68
|
+
type FieldType = 'string' | 'text' | 'richtext' | 'integer' | 'bigint' | 'decimal' | 'boolean' | 'date' | 'datetime' | 'json' | 'enum' | 'relation' | 'component' | 'media';
|
|
69
|
+
interface ACmsField {
|
|
70
|
+
type: FieldType;
|
|
71
|
+
required?: boolean;
|
|
72
|
+
unique?: boolean;
|
|
73
|
+
default?: unknown;
|
|
74
|
+
minLength?: number;
|
|
75
|
+
maxLength?: number;
|
|
76
|
+
min?: number;
|
|
77
|
+
max?: number;
|
|
78
|
+
enum?: string[];
|
|
79
|
+
target?: string;
|
|
80
|
+
relation?: 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany';
|
|
81
|
+
mappedBy?: string;
|
|
82
|
+
inversedBy?: string;
|
|
83
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT';
|
|
84
|
+
component?: string;
|
|
85
|
+
repeatable?: boolean;
|
|
86
|
+
index?: boolean | 'unique' | 'fulltext';
|
|
87
|
+
foreignKey?: {
|
|
88
|
+
table: string;
|
|
89
|
+
field: string;
|
|
90
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
91
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
interface ACmsSchema {
|
|
95
|
+
kind: 'collectionType' | 'singleType';
|
|
96
|
+
info: {
|
|
97
|
+
singularName: string;
|
|
98
|
+
pluralName: string;
|
|
99
|
+
displayName: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
};
|
|
102
|
+
options?: {
|
|
103
|
+
draftAndPublish?: boolean;
|
|
104
|
+
timestamps?: boolean;
|
|
105
|
+
softDelete?: boolean;
|
|
106
|
+
};
|
|
107
|
+
attributes: Record<string, ACmsField>;
|
|
108
|
+
indexes?: Array<{
|
|
109
|
+
fields: string[];
|
|
110
|
+
type: 'index' | 'unique' | 'fulltext';
|
|
111
|
+
name?: string;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Пример схемы в универсальном формате
|
|
116
|
+
*/
|
|
117
|
+
declare const exampleSchema: ACmsSchema;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Validation types for ACms Schema
|
|
121
|
+
*/
|
|
122
|
+
interface ValidationError {
|
|
123
|
+
field: string;
|
|
124
|
+
message: string;
|
|
125
|
+
code: ValidationErrorCode;
|
|
126
|
+
details?: unknown;
|
|
127
|
+
}
|
|
128
|
+
type ValidationErrorCode = 'MISSING_REQUIRED_FIELD' | 'INVALID_FIELD_TYPE' | 'INVALID_RELATION_TYPE' | 'DUPLICATE_FIELD_NAME' | 'INVALID_CONSTRAINT' | 'INVALID_ENUM_VALUES' | 'INVALID_RELATION_TARGET' | 'INVALID_RELATION_INVERSE' | 'MISSING_INFO' | 'EMPTY_ATTRIBUTES' | 'INVALID_MIN_MAX' | 'INVALID_LENGTH_CONSTRAINT' | 'INVALID_INDEX_TYPE' | 'INVALID_FOREIGN_KEY' | 'INVALID_INDEX_FIELDS';
|
|
129
|
+
interface ValidationResult {
|
|
130
|
+
valid: boolean;
|
|
131
|
+
errors: ValidationError[];
|
|
132
|
+
}
|
|
133
|
+
declare class SchemaValidationError extends Error {
|
|
134
|
+
result: ValidationResult;
|
|
135
|
+
constructor(result: ValidationResult, message?: string);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Migration types for ACms Database
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* Database connection for migrations
|
|
143
|
+
* Union type supporting SQLite, PostgreSQL, and MySQL
|
|
144
|
+
*/
|
|
145
|
+
type MigrationDatabaseConnection = SQLiteMigrationConnection | PostgresMigrationConnection | MySQLMigrationConnection;
|
|
146
|
+
/**
|
|
147
|
+
* SQLite database connection for migrations
|
|
148
|
+
*/
|
|
149
|
+
interface SQLiteMigrationConnection {
|
|
150
|
+
exec(sql: string): void;
|
|
151
|
+
prepare(sql: string): {
|
|
152
|
+
run(...params: unknown[]): void;
|
|
153
|
+
all(...params: unknown[]): unknown[];
|
|
154
|
+
get(...params: unknown[]): unknown;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* PostgreSQL database connection for migrations
|
|
159
|
+
*/
|
|
160
|
+
interface PostgresMigrationConnection {
|
|
161
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
162
|
+
rows?: unknown[];
|
|
163
|
+
rowCount?: number;
|
|
164
|
+
}>;
|
|
165
|
+
query(sql: string, params?: unknown[]): Promise<{
|
|
166
|
+
rows: unknown[];
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* MySQL database connection for migrations
|
|
171
|
+
*/
|
|
172
|
+
interface MySQLMigrationConnection {
|
|
173
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
174
|
+
rows?: unknown[];
|
|
175
|
+
insertId?: number;
|
|
176
|
+
affectedRows?: number;
|
|
177
|
+
}>;
|
|
178
|
+
query(sql: string, params?: unknown[]): Promise<unknown[]>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Migration interface - структура файла миграции
|
|
182
|
+
*/
|
|
183
|
+
interface Migration {
|
|
184
|
+
up: (db: MigrationDatabaseConnection) => Promise<void>;
|
|
185
|
+
down: (db: MigrationDatabaseConnection) => Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Migration record - запись в таблице _migrations
|
|
189
|
+
*/
|
|
190
|
+
interface MigrationRecord {
|
|
191
|
+
id: number;
|
|
192
|
+
name: string;
|
|
193
|
+
timestamp: string;
|
|
194
|
+
batch: number;
|
|
195
|
+
executedAt: Date;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Migration status - статус отдельной миграции
|
|
199
|
+
*/
|
|
200
|
+
interface MigrationStatus {
|
|
201
|
+
name: string;
|
|
202
|
+
timestamp: string;
|
|
203
|
+
status: 'pending' | 'executed';
|
|
204
|
+
batch?: number;
|
|
205
|
+
executedAt?: Date;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Migration result - результат выполнения миграции
|
|
209
|
+
*/
|
|
210
|
+
interface MigrationResult {
|
|
211
|
+
success: boolean;
|
|
212
|
+
migrationsRun: string[];
|
|
213
|
+
errors?: string[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Rollback result - результат отката миграций
|
|
217
|
+
*/
|
|
218
|
+
interface RollbackResult {
|
|
219
|
+
success: boolean;
|
|
220
|
+
migrationsRolledBack: string[];
|
|
221
|
+
errors?: string[];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { type ACmsField, type ACmsSchema, type ContentEntry, type FieldType, type Migration, type MigrationDatabaseConnection, type MigrationRecord, type MigrationResult, type MigrationStatus, type MySQLMigrationConnection, type Plugin, type PluginHooks, type PostgresMigrationConnection, type QueryOptions, type RollbackResult, type SQLiteMigrationConnection, SchemaValidationError, type Theme, type ThemeConfig, type User, type ValidationError, type ValidationErrorCode, type ValidationResult, exampleSchema };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Types
|
|
3
|
+
*/
|
|
4
|
+
interface ContentEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
publishedAt?: Date;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface QueryOptions {
|
|
12
|
+
filters?: Record<string, unknown>;
|
|
13
|
+
sort?: string[];
|
|
14
|
+
pagination?: {
|
|
15
|
+
page: number;
|
|
16
|
+
pageSize: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* User Types
|
|
22
|
+
*/
|
|
23
|
+
interface User {
|
|
24
|
+
id: string;
|
|
25
|
+
email: string;
|
|
26
|
+
username: string;
|
|
27
|
+
role: 'admin' | 'editor' | 'viewer';
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Plugin Types
|
|
34
|
+
*/
|
|
35
|
+
interface Plugin {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
config?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
interface PluginHooks {
|
|
42
|
+
beforeCreate?: (data: unknown) => Promise<unknown>;
|
|
43
|
+
afterCreate?: (data: unknown) => Promise<void>;
|
|
44
|
+
beforeUpdate?: (id: string, data: unknown) => Promise<unknown>;
|
|
45
|
+
afterUpdate?: (id: string, data: unknown) => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Theme Types
|
|
50
|
+
*/
|
|
51
|
+
interface Theme {
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
description: string;
|
|
55
|
+
author: string;
|
|
56
|
+
templates: string[];
|
|
57
|
+
}
|
|
58
|
+
interface ThemeConfig {
|
|
59
|
+
colors?: Record<string, string>;
|
|
60
|
+
fonts?: Record<string, string>;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* ACms Universal Schema Format
|
|
66
|
+
* Аналог Strapi schema, но адаптированный для Drizzle
|
|
67
|
+
*/
|
|
68
|
+
type FieldType = 'string' | 'text' | 'richtext' | 'integer' | 'bigint' | 'decimal' | 'boolean' | 'date' | 'datetime' | 'json' | 'enum' | 'relation' | 'component' | 'media';
|
|
69
|
+
interface ACmsField {
|
|
70
|
+
type: FieldType;
|
|
71
|
+
required?: boolean;
|
|
72
|
+
unique?: boolean;
|
|
73
|
+
default?: unknown;
|
|
74
|
+
minLength?: number;
|
|
75
|
+
maxLength?: number;
|
|
76
|
+
min?: number;
|
|
77
|
+
max?: number;
|
|
78
|
+
enum?: string[];
|
|
79
|
+
target?: string;
|
|
80
|
+
relation?: 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany';
|
|
81
|
+
mappedBy?: string;
|
|
82
|
+
inversedBy?: string;
|
|
83
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT';
|
|
84
|
+
component?: string;
|
|
85
|
+
repeatable?: boolean;
|
|
86
|
+
index?: boolean | 'unique' | 'fulltext';
|
|
87
|
+
foreignKey?: {
|
|
88
|
+
table: string;
|
|
89
|
+
field: string;
|
|
90
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
91
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
interface ACmsSchema {
|
|
95
|
+
kind: 'collectionType' | 'singleType';
|
|
96
|
+
info: {
|
|
97
|
+
singularName: string;
|
|
98
|
+
pluralName: string;
|
|
99
|
+
displayName: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
};
|
|
102
|
+
options?: {
|
|
103
|
+
draftAndPublish?: boolean;
|
|
104
|
+
timestamps?: boolean;
|
|
105
|
+
softDelete?: boolean;
|
|
106
|
+
};
|
|
107
|
+
attributes: Record<string, ACmsField>;
|
|
108
|
+
indexes?: Array<{
|
|
109
|
+
fields: string[];
|
|
110
|
+
type: 'index' | 'unique' | 'fulltext';
|
|
111
|
+
name?: string;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Пример схемы в универсальном формате
|
|
116
|
+
*/
|
|
117
|
+
declare const exampleSchema: ACmsSchema;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Validation types for ACms Schema
|
|
121
|
+
*/
|
|
122
|
+
interface ValidationError {
|
|
123
|
+
field: string;
|
|
124
|
+
message: string;
|
|
125
|
+
code: ValidationErrorCode;
|
|
126
|
+
details?: unknown;
|
|
127
|
+
}
|
|
128
|
+
type ValidationErrorCode = 'MISSING_REQUIRED_FIELD' | 'INVALID_FIELD_TYPE' | 'INVALID_RELATION_TYPE' | 'DUPLICATE_FIELD_NAME' | 'INVALID_CONSTRAINT' | 'INVALID_ENUM_VALUES' | 'INVALID_RELATION_TARGET' | 'INVALID_RELATION_INVERSE' | 'MISSING_INFO' | 'EMPTY_ATTRIBUTES' | 'INVALID_MIN_MAX' | 'INVALID_LENGTH_CONSTRAINT' | 'INVALID_INDEX_TYPE' | 'INVALID_FOREIGN_KEY' | 'INVALID_INDEX_FIELDS';
|
|
129
|
+
interface ValidationResult {
|
|
130
|
+
valid: boolean;
|
|
131
|
+
errors: ValidationError[];
|
|
132
|
+
}
|
|
133
|
+
declare class SchemaValidationError extends Error {
|
|
134
|
+
result: ValidationResult;
|
|
135
|
+
constructor(result: ValidationResult, message?: string);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Migration types for ACms Database
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* Database connection for migrations
|
|
143
|
+
* Union type supporting SQLite, PostgreSQL, and MySQL
|
|
144
|
+
*/
|
|
145
|
+
type MigrationDatabaseConnection = SQLiteMigrationConnection | PostgresMigrationConnection | MySQLMigrationConnection;
|
|
146
|
+
/**
|
|
147
|
+
* SQLite database connection for migrations
|
|
148
|
+
*/
|
|
149
|
+
interface SQLiteMigrationConnection {
|
|
150
|
+
exec(sql: string): void;
|
|
151
|
+
prepare(sql: string): {
|
|
152
|
+
run(...params: unknown[]): void;
|
|
153
|
+
all(...params: unknown[]): unknown[];
|
|
154
|
+
get(...params: unknown[]): unknown;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* PostgreSQL database connection for migrations
|
|
159
|
+
*/
|
|
160
|
+
interface PostgresMigrationConnection {
|
|
161
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
162
|
+
rows?: unknown[];
|
|
163
|
+
rowCount?: number;
|
|
164
|
+
}>;
|
|
165
|
+
query(sql: string, params?: unknown[]): Promise<{
|
|
166
|
+
rows: unknown[];
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* MySQL database connection for migrations
|
|
171
|
+
*/
|
|
172
|
+
interface MySQLMigrationConnection {
|
|
173
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
174
|
+
rows?: unknown[];
|
|
175
|
+
insertId?: number;
|
|
176
|
+
affectedRows?: number;
|
|
177
|
+
}>;
|
|
178
|
+
query(sql: string, params?: unknown[]): Promise<unknown[]>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Migration interface - структура файла миграции
|
|
182
|
+
*/
|
|
183
|
+
interface Migration {
|
|
184
|
+
up: (db: MigrationDatabaseConnection) => Promise<void>;
|
|
185
|
+
down: (db: MigrationDatabaseConnection) => Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Migration record - запись в таблице _migrations
|
|
189
|
+
*/
|
|
190
|
+
interface MigrationRecord {
|
|
191
|
+
id: number;
|
|
192
|
+
name: string;
|
|
193
|
+
timestamp: string;
|
|
194
|
+
batch: number;
|
|
195
|
+
executedAt: Date;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Migration status - статус отдельной миграции
|
|
199
|
+
*/
|
|
200
|
+
interface MigrationStatus {
|
|
201
|
+
name: string;
|
|
202
|
+
timestamp: string;
|
|
203
|
+
status: 'pending' | 'executed';
|
|
204
|
+
batch?: number;
|
|
205
|
+
executedAt?: Date;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Migration result - результат выполнения миграции
|
|
209
|
+
*/
|
|
210
|
+
interface MigrationResult {
|
|
211
|
+
success: boolean;
|
|
212
|
+
migrationsRun: string[];
|
|
213
|
+
errors?: string[];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Rollback result - результат отката миграций
|
|
217
|
+
*/
|
|
218
|
+
interface RollbackResult {
|
|
219
|
+
success: boolean;
|
|
220
|
+
migrationsRolledBack: string[];
|
|
221
|
+
errors?: string[];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { type ACmsField, type ACmsSchema, type ContentEntry, type FieldType, type Migration, type MigrationDatabaseConnection, type MigrationRecord, type MigrationResult, type MigrationStatus, type MySQLMigrationConnection, type Plugin, type PluginHooks, type PostgresMigrationConnection, type QueryOptions, type RollbackResult, type SQLiteMigrationConnection, SchemaValidationError, type Theme, type ThemeConfig, type User, type ValidationError, type ValidationErrorCode, type ValidationResult, exampleSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/acms-schema.ts
|
|
2
|
+
var exampleSchema = {
|
|
3
|
+
kind: "collectionType",
|
|
4
|
+
info: {
|
|
5
|
+
singularName: "article",
|
|
6
|
+
pluralName: "articles",
|
|
7
|
+
displayName: "Article",
|
|
8
|
+
description: "Blog articles"
|
|
9
|
+
},
|
|
10
|
+
options: {
|
|
11
|
+
draftAndPublish: true,
|
|
12
|
+
timestamps: true
|
|
13
|
+
},
|
|
14
|
+
attributes: {
|
|
15
|
+
title: {
|
|
16
|
+
type: "string",
|
|
17
|
+
required: true,
|
|
18
|
+
maxLength: 255
|
|
19
|
+
},
|
|
20
|
+
slug: {
|
|
21
|
+
type: "string",
|
|
22
|
+
required: true,
|
|
23
|
+
unique: true,
|
|
24
|
+
maxLength: 255
|
|
25
|
+
},
|
|
26
|
+
content: {
|
|
27
|
+
type: "richtext",
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
publishedAt: {
|
|
31
|
+
type: "datetime"
|
|
32
|
+
},
|
|
33
|
+
author: {
|
|
34
|
+
type: "relation",
|
|
35
|
+
relation: "manyToOne",
|
|
36
|
+
target: "users"
|
|
37
|
+
},
|
|
38
|
+
categories: {
|
|
39
|
+
type: "relation",
|
|
40
|
+
relation: "manyToMany",
|
|
41
|
+
target: "categories"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/validation.ts
|
|
47
|
+
var SchemaValidationError = class extends Error {
|
|
48
|
+
constructor(result, message) {
|
|
49
|
+
super(message || "Schema validation failed");
|
|
50
|
+
this.result = result;
|
|
51
|
+
this.name = "SchemaValidationError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
SchemaValidationError,
|
|
56
|
+
exampleSchema
|
|
57
|
+
};
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/acms-schema.ts
|
|
2
|
+
var exampleSchema = {
|
|
3
|
+
kind: "collectionType",
|
|
4
|
+
info: {
|
|
5
|
+
singularName: "article",
|
|
6
|
+
pluralName: "articles",
|
|
7
|
+
displayName: "Article",
|
|
8
|
+
description: "Blog articles"
|
|
9
|
+
},
|
|
10
|
+
options: {
|
|
11
|
+
draftAndPublish: true,
|
|
12
|
+
timestamps: true
|
|
13
|
+
},
|
|
14
|
+
attributes: {
|
|
15
|
+
title: {
|
|
16
|
+
type: "string",
|
|
17
|
+
required: true,
|
|
18
|
+
maxLength: 255
|
|
19
|
+
},
|
|
20
|
+
slug: {
|
|
21
|
+
type: "string",
|
|
22
|
+
required: true,
|
|
23
|
+
unique: true,
|
|
24
|
+
maxLength: 255
|
|
25
|
+
},
|
|
26
|
+
content: {
|
|
27
|
+
type: "richtext",
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
publishedAt: {
|
|
31
|
+
type: "datetime"
|
|
32
|
+
},
|
|
33
|
+
author: {
|
|
34
|
+
type: "relation",
|
|
35
|
+
relation: "manyToOne",
|
|
36
|
+
target: "users"
|
|
37
|
+
},
|
|
38
|
+
categories: {
|
|
39
|
+
type: "relation",
|
|
40
|
+
relation: "manyToMany",
|
|
41
|
+
target: "categories"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/validation.ts
|
|
47
|
+
var SchemaValidationError = class extends Error {
|
|
48
|
+
constructor(result, message) {
|
|
49
|
+
super(message || "Schema validation failed");
|
|
50
|
+
this.result = result;
|
|
51
|
+
this.name = "SchemaValidationError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
SchemaValidationError,
|
|
56
|
+
exampleSchema
|
|
57
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@notty/types",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared TypeScript types for Notty CMS",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "restricted"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsup": "^8.3.0",
|
|
24
|
+
"typescript": "^5.6.3"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
28
|
+
"build:libs": "tsup src/index.ts --format cjs,esm --dts",
|
|
29
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
30
|
+
"lint": "eslint src",
|
|
31
|
+
"type-check": "tsc --noEmit",
|
|
32
|
+
"clean": "rm -rf dist"
|
|
33
|
+
}
|
|
34
|
+
}
|