@dooor-ai/cortexdb 0.6.1 → 0.6.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/README.md +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/schema-cli/index.js +889 -14
- package/dist/schema-cli/index.js.map +1 -1
- package/dist/schema-decorators/decorators.d.ts +175 -0
- package/dist/schema-decorators/decorators.d.ts.map +1 -0
- package/dist/schema-decorators/decorators.js +277 -0
- package/dist/schema-decorators/decorators.js.map +1 -0
- package/dist/schema-decorators/index.d.ts +10 -0
- package/dist/schema-decorators/index.d.ts.map +1 -0
- package/dist/schema-decorators/index.js +25 -0
- package/dist/schema-decorators/index.js.map +1 -0
- package/dist/schema-decorators/loader.d.ts +12 -0
- package/dist/schema-decorators/loader.d.ts.map +1 -0
- package/dist/schema-decorators/loader.js +161 -0
- package/dist/schema-decorators/loader.js.map +1 -0
- package/dist/schema-decorators/validator.d.ts +26 -0
- package/dist/schema-decorators/validator.d.ts.map +1 -0
- package/dist/schema-decorators/validator.js +193 -0
- package/dist/schema-decorators/validator.js.map +1 -0
- package/package.json +18 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collection = Collection;
|
|
4
|
+
exports.Field = Field;
|
|
5
|
+
exports.getCollectionMetadata = getCollectionMetadata;
|
|
6
|
+
exports.getFieldMetadata = getFieldMetadata;
|
|
7
|
+
exports.clearMetadata = clearMetadata;
|
|
8
|
+
exports.getRelationshipMetadata = getRelationshipMetadata;
|
|
9
|
+
exports.getAllRelationshipMetadata = getAllRelationshipMetadata;
|
|
10
|
+
exports.fieldMetadataToDefinition = fieldMetadataToDefinition;
|
|
11
|
+
exports.ManyToOne = ManyToOne;
|
|
12
|
+
exports.OneToOne = OneToOne;
|
|
13
|
+
exports.OneToMany = OneToMany;
|
|
14
|
+
exports.ManyToMany = ManyToMany;
|
|
15
|
+
const types_1 = require("../types");
|
|
16
|
+
const collectionMetadata = new Map();
|
|
17
|
+
const fieldMetadata = new Map();
|
|
18
|
+
const relationshipMetadata = new Map();
|
|
19
|
+
function Collection(options) {
|
|
20
|
+
return function (target) {
|
|
21
|
+
const className = target.name;
|
|
22
|
+
collectionMetadata.set(className, {
|
|
23
|
+
name: options.name,
|
|
24
|
+
description: options.description,
|
|
25
|
+
database: options.database,
|
|
26
|
+
config: options.config,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function Field(options) {
|
|
31
|
+
return function (target, propertyKey) {
|
|
32
|
+
const key = String(propertyKey);
|
|
33
|
+
const prototype = target;
|
|
34
|
+
const constructor = Object.getPrototypeOf(prototype).constructor;
|
|
35
|
+
if (!constructor || constructor === Object) {
|
|
36
|
+
const targetConstructor = prototype.constructor;
|
|
37
|
+
if (!targetConstructor) {
|
|
38
|
+
throw new Error(`Cannot determine constructor for field ${key}`);
|
|
39
|
+
}
|
|
40
|
+
if (!fieldMetadata.has(targetConstructor)) {
|
|
41
|
+
fieldMetadata.set(targetConstructor, []);
|
|
42
|
+
}
|
|
43
|
+
const fields = fieldMetadata.get(targetConstructor);
|
|
44
|
+
fields.push({
|
|
45
|
+
name: key,
|
|
46
|
+
type: options.type,
|
|
47
|
+
description: options.description,
|
|
48
|
+
required: options.required ?? false,
|
|
49
|
+
indexed: options.indexed ?? false,
|
|
50
|
+
unique: options.unique ?? false,
|
|
51
|
+
filterable: options.filterable ?? false,
|
|
52
|
+
vectorize: options.vectorize ?? false,
|
|
53
|
+
default: options.default,
|
|
54
|
+
values: options.values,
|
|
55
|
+
storeIn: options.storeIn,
|
|
56
|
+
extractConfig: options.extractConfig,
|
|
57
|
+
schema: options.schema,
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!fieldMetadata.has(constructor)) {
|
|
62
|
+
fieldMetadata.set(constructor, []);
|
|
63
|
+
}
|
|
64
|
+
const fields = fieldMetadata.get(constructor);
|
|
65
|
+
fields.push({
|
|
66
|
+
name: key,
|
|
67
|
+
type: options.type,
|
|
68
|
+
description: options.description,
|
|
69
|
+
required: options.required ?? false,
|
|
70
|
+
indexed: options.indexed ?? false,
|
|
71
|
+
unique: options.unique ?? false,
|
|
72
|
+
filterable: options.filterable ?? false,
|
|
73
|
+
vectorize: options.vectorize ?? false,
|
|
74
|
+
default: options.default,
|
|
75
|
+
values: options.values,
|
|
76
|
+
storeIn: options.storeIn,
|
|
77
|
+
extractConfig: options.extractConfig,
|
|
78
|
+
schema: options.schema,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function getCollectionMetadata() {
|
|
83
|
+
return collectionMetadata;
|
|
84
|
+
}
|
|
85
|
+
function getFieldMetadata(target) {
|
|
86
|
+
return fieldMetadata.get(target);
|
|
87
|
+
}
|
|
88
|
+
function clearMetadata() {
|
|
89
|
+
collectionMetadata.clear();
|
|
90
|
+
fieldMetadata.clear();
|
|
91
|
+
relationshipMetadata.clear();
|
|
92
|
+
}
|
|
93
|
+
function getRelationshipMetadata(target) {
|
|
94
|
+
return relationshipMetadata.get(target);
|
|
95
|
+
}
|
|
96
|
+
function getAllRelationshipMetadata() {
|
|
97
|
+
return relationshipMetadata;
|
|
98
|
+
}
|
|
99
|
+
function fieldMetadataToDefinition(field) {
|
|
100
|
+
return {
|
|
101
|
+
name: field.name,
|
|
102
|
+
type: field.type,
|
|
103
|
+
description: field.description,
|
|
104
|
+
required: field.required,
|
|
105
|
+
indexed: field.indexed,
|
|
106
|
+
unique: field.unique,
|
|
107
|
+
filterable: field.filterable,
|
|
108
|
+
vectorize: field.vectorize,
|
|
109
|
+
default: field.default,
|
|
110
|
+
values: field.values,
|
|
111
|
+
store_in: field.storeIn,
|
|
112
|
+
extract_config: field.extractConfig,
|
|
113
|
+
schema: field.schema,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Many-to-One relationship (N:1)
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* @Collection({ name: "posts" })
|
|
122
|
+
* class Post {
|
|
123
|
+
* @ManyToOne({
|
|
124
|
+
* target: () => User,
|
|
125
|
+
* required: true,
|
|
126
|
+
* indexed: true
|
|
127
|
+
* })
|
|
128
|
+
* author!: User; // Creates author_id foreign key
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function ManyToOne(options) {
|
|
133
|
+
return function (target, propertyKey) {
|
|
134
|
+
const key = String(propertyKey);
|
|
135
|
+
const foreignKey = options.foreignKey || `${key}_id`;
|
|
136
|
+
const prototype = target;
|
|
137
|
+
const constructor = Object.getPrototypeOf(prototype).constructor;
|
|
138
|
+
if (!fieldMetadata.has(constructor)) {
|
|
139
|
+
fieldMetadata.set(constructor, []);
|
|
140
|
+
}
|
|
141
|
+
const fields = fieldMetadata.get(constructor);
|
|
142
|
+
// Add foreign key field
|
|
143
|
+
fields.push({
|
|
144
|
+
name: foreignKey,
|
|
145
|
+
type: types_1.FieldType.STRING,
|
|
146
|
+
description: options.description || `Foreign key to ${key}`,
|
|
147
|
+
required: options.required ?? false,
|
|
148
|
+
indexed: options.indexed ?? true, // Index by default for performance
|
|
149
|
+
unique: false,
|
|
150
|
+
filterable: options.filterable ?? true, // Enable filtering by default
|
|
151
|
+
vectorize: false,
|
|
152
|
+
storeIn: [types_1.StoreLocation.POSTGRES, types_1.StoreLocation.QDRANT_PAYLOAD],
|
|
153
|
+
});
|
|
154
|
+
// Store relationship metadata for validation
|
|
155
|
+
if (!relationshipMetadata.has(constructor)) {
|
|
156
|
+
relationshipMetadata.set(constructor, []);
|
|
157
|
+
}
|
|
158
|
+
const relationships = relationshipMetadata.get(constructor);
|
|
159
|
+
const targetClass = options.target();
|
|
160
|
+
relationships.push({
|
|
161
|
+
fieldName: key,
|
|
162
|
+
type: 'ManyToOne',
|
|
163
|
+
targetClassName: targetClass.name,
|
|
164
|
+
foreignKey,
|
|
165
|
+
required: options.required,
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* One-to-One relationship (1:1)
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* @Collection({ name: "users" })
|
|
175
|
+
* class User {
|
|
176
|
+
* @OneToOne({
|
|
177
|
+
* target: () => Profile,
|
|
178
|
+
* owner: true,
|
|
179
|
+
* required: false
|
|
180
|
+
* })
|
|
181
|
+
* profile?: Profile; // Creates profile_id foreign key
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
function OneToOne(options) {
|
|
186
|
+
return function (target, propertyKey) {
|
|
187
|
+
// Only create foreign key on the owning side
|
|
188
|
+
if (options.owner === false) {
|
|
189
|
+
return; // Non-owning side, no field needed
|
|
190
|
+
}
|
|
191
|
+
const key = String(propertyKey);
|
|
192
|
+
const foreignKey = options.foreignKey || `${key}_id`;
|
|
193
|
+
const prototype = target;
|
|
194
|
+
const constructor = Object.getPrototypeOf(prototype).constructor;
|
|
195
|
+
if (!fieldMetadata.has(constructor)) {
|
|
196
|
+
fieldMetadata.set(constructor, []);
|
|
197
|
+
}
|
|
198
|
+
const fields = fieldMetadata.get(constructor);
|
|
199
|
+
// Add foreign key field with unique constraint
|
|
200
|
+
fields.push({
|
|
201
|
+
name: foreignKey,
|
|
202
|
+
type: types_1.FieldType.STRING,
|
|
203
|
+
description: options.description || `Foreign key to ${key} (1:1)`,
|
|
204
|
+
required: options.required ?? false,
|
|
205
|
+
indexed: true,
|
|
206
|
+
unique: true, // 1:1 requires uniqueness
|
|
207
|
+
filterable: options.filterable ?? true,
|
|
208
|
+
vectorize: false,
|
|
209
|
+
storeIn: [types_1.StoreLocation.POSTGRES, types_1.StoreLocation.QDRANT_PAYLOAD],
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* One-to-Many relationship (1:N)
|
|
215
|
+
* This is informational only - the foreign key exists on the "many" side
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* @Collection({ name: "users" })
|
|
220
|
+
* class User {
|
|
221
|
+
* @OneToMany({
|
|
222
|
+
* target: () => Post,
|
|
223
|
+
* foreignKey: "author_id"
|
|
224
|
+
* })
|
|
225
|
+
* posts?: Post[]; // Virtual field, no FK created here
|
|
226
|
+
* }
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
function OneToMany(options) {
|
|
230
|
+
return function (target, propertyKey) {
|
|
231
|
+
// OneToMany doesn't create any fields - it's just metadata
|
|
232
|
+
// The foreign key lives on the "many" side (target collection)
|
|
233
|
+
// This decorator is mainly for documentation and future query building
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Many-to-Many relationship (N:N)
|
|
238
|
+
* Creates a join table to manage the relationship
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* @Collection({ name: "posts" })
|
|
243
|
+
* class Post {
|
|
244
|
+
* @ManyToMany({
|
|
245
|
+
* target: () => Tag,
|
|
246
|
+
* joinTable: "post_tags"
|
|
247
|
+
* })
|
|
248
|
+
* tags?: Tag[]; // Join table: post_tags(post_id, tag_id)
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
function ManyToMany(options) {
|
|
253
|
+
return function (target, propertyKey) {
|
|
254
|
+
// ManyToMany relationships require a join table
|
|
255
|
+
// This is handled by storing an array of IDs in a JSONB field
|
|
256
|
+
const key = String(propertyKey);
|
|
257
|
+
const prototype = target;
|
|
258
|
+
const constructor = Object.getPrototypeOf(prototype).constructor;
|
|
259
|
+
if (!fieldMetadata.has(constructor)) {
|
|
260
|
+
fieldMetadata.set(constructor, []);
|
|
261
|
+
}
|
|
262
|
+
const fields = fieldMetadata.get(constructor);
|
|
263
|
+
// Store as array of IDs in JSONB
|
|
264
|
+
fields.push({
|
|
265
|
+
name: `${key}_ids`,
|
|
266
|
+
type: types_1.FieldType.JSON,
|
|
267
|
+
description: options.description || `Many-to-many relationship with ${key}`,
|
|
268
|
+
required: false,
|
|
269
|
+
indexed: false,
|
|
270
|
+
unique: false,
|
|
271
|
+
filterable: false,
|
|
272
|
+
vectorize: false,
|
|
273
|
+
storeIn: [types_1.StoreLocation.POSTGRES],
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/schema-decorators/decorators.ts"],"names":[],"mappings":";;AAqEA,gCAUC;AAED,sBAsDC;AAED,sDAEC;AAED,4CAEC;AAED,sCAIC;AAED,0DAEC;AAED,gEAEC;AAED,8DAgBC;AAiED,8BAyCC;AAkBD,4BAgCC;AAkBD,8BAMC;AAkBD,gCA4BC;AAjZD,oCAAuF;AAEvF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA8B,CAAC;AACjE,MAAM,aAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;AACzD,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAkC,CAAC;AAiEvE,SAAgB,UAAU,CAAC,OAA0B;IACnD,OAAO,UAAU,MAAwB;QACvC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;QAC9B,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB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AM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC;QAEjE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACpC,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;QAE/C,iCAAiC;QACjC,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,GAAG,GAAG,MAAM;YAClB,IAAI,EAAE,iBAAS,CAAC,IAAI;YACpB,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,kCAAkC,GAAG,EAAE;YAC3E,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,CAAC,qBAAa,CAAC,QAAQ,CAAC;SAClC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Decorators for CortexDB
|
|
3
|
+
*
|
|
4
|
+
* Define schemas using TypeScript decorators instead of YAML files.
|
|
5
|
+
*/
|
|
6
|
+
export { Collection, Field, FieldOptions, CollectionOptions, ManyToOne, OneToOne, OneToMany, ManyToMany, ManyToOneOptions, OneToOneOptions, OneToManyOptions, ManyToManyOptions, RelationOptions, } from './decorators';
|
|
7
|
+
export { loadTypeScriptSchemasSync, LoadedCollection } from './loader';
|
|
8
|
+
export { validateSchema, formatValidationErrors, ValidationError, ValidationResult } from './validator';
|
|
9
|
+
export { FieldType, StoreLocation, FieldDefinition, CollectionConfig } from '../types';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema-decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,KAAK,EACL,YAAY,EACZ,iBAAiB,EAEjB,SAAS,EACT,QAAQ,EACR,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Schema Decorators for CortexDB
|
|
4
|
+
*
|
|
5
|
+
* Define schemas using TypeScript decorators instead of YAML files.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.StoreLocation = exports.FieldType = exports.formatValidationErrors = exports.validateSchema = exports.loadTypeScriptSchemasSync = exports.ManyToMany = exports.OneToMany = exports.OneToOne = exports.ManyToOne = exports.Field = exports.Collection = void 0;
|
|
9
|
+
var decorators_1 = require("./decorators");
|
|
10
|
+
Object.defineProperty(exports, "Collection", { enumerable: true, get: function () { return decorators_1.Collection; } });
|
|
11
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return decorators_1.Field; } });
|
|
12
|
+
// Relationship decorators
|
|
13
|
+
Object.defineProperty(exports, "ManyToOne", { enumerable: true, get: function () { return decorators_1.ManyToOne; } });
|
|
14
|
+
Object.defineProperty(exports, "OneToOne", { enumerable: true, get: function () { return decorators_1.OneToOne; } });
|
|
15
|
+
Object.defineProperty(exports, "OneToMany", { enumerable: true, get: function () { return decorators_1.OneToMany; } });
|
|
16
|
+
Object.defineProperty(exports, "ManyToMany", { enumerable: true, get: function () { return decorators_1.ManyToMany; } });
|
|
17
|
+
var loader_1 = require("./loader");
|
|
18
|
+
Object.defineProperty(exports, "loadTypeScriptSchemasSync", { enumerable: true, get: function () { return loader_1.loadTypeScriptSchemasSync; } });
|
|
19
|
+
var validator_1 = require("./validator");
|
|
20
|
+
Object.defineProperty(exports, "validateSchema", { enumerable: true, get: function () { return validator_1.validateSchema; } });
|
|
21
|
+
Object.defineProperty(exports, "formatValidationErrors", { enumerable: true, get: function () { return validator_1.formatValidationErrors; } });
|
|
22
|
+
var types_1 = require("../types");
|
|
23
|
+
Object.defineProperty(exports, "FieldType", { enumerable: true, get: function () { return types_1.FieldType; } });
|
|
24
|
+
Object.defineProperty(exports, "StoreLocation", { enumerable: true, get: function () { return types_1.StoreLocation; } });
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema-decorators/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,2CAesB;AAdpB,wGAAA,UAAU,OAAA;AACV,mGAAA,KAAK,OAAA;AAGL,0BAA0B;AAC1B,uGAAA,SAAS,OAAA;AACT,sGAAA,QAAQ,OAAA;AACR,uGAAA,SAAS,OAAA;AACT,wGAAA,UAAU,OAAA;AAOZ,mCAAuE;AAA9D,mHAAA,yBAAyB,OAAA;AAClC,yCAAwG;AAA/F,2GAAA,cAAc,OAAA;AAAE,mHAAA,sBAAsB,OAAA;AAC/C,kCAAuF;AAA9E,kGAAA,SAAS,OAAA;AAAE,sGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FieldDefinition, CollectionConfig } from '../types';
|
|
2
|
+
export interface LoadedCollection {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
database?: string;
|
|
6
|
+
config?: CollectionConfig;
|
|
7
|
+
fields: FieldDefinition[];
|
|
8
|
+
/** Original TypeScript class name (for validation) */
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function loadTypeScriptSchemasSync(schemaDir: string): LoadedCollection[];
|
|
12
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/schema-decorators/loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAa7D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0BD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAkG/E"}
|
|
@@ -0,0 +1,161 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadTypeScriptSchemasSync = loadTypeScriptSchemasSync;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const decorators_1 = require("./decorators");
|
|
40
|
+
let tsNodeAvailable = false;
|
|
41
|
+
try {
|
|
42
|
+
// Try to resolve ts-node from the current working directory first
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
44
|
+
require.resolve('ts-node', { paths: [process.cwd(), __dirname] });
|
|
45
|
+
tsNodeAvailable = true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// ts-node not available
|
|
49
|
+
}
|
|
50
|
+
function registerTsNode() {
|
|
51
|
+
if (tsNodeAvailable && !global.__tsNodeRegistered) {
|
|
52
|
+
try {
|
|
53
|
+
// Try to load ts-node from the current working directory
|
|
54
|
+
const tsNodePath = require.resolve('ts-node', { paths: [process.cwd(), __dirname] });
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
56
|
+
const tsNode = require(tsNodePath);
|
|
57
|
+
tsNode.register({
|
|
58
|
+
transpileOnly: true,
|
|
59
|
+
compilerOptions: {
|
|
60
|
+
module: 'commonjs',
|
|
61
|
+
target: 'es2020',
|
|
62
|
+
esModuleInterop: true,
|
|
63
|
+
experimentalDecorators: true,
|
|
64
|
+
emitDecoratorMetadata: true,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
global.__tsNodeRegistered = true;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// ts-node registration failed
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function loadTypeScriptSchemasSync(schemaDir) {
|
|
75
|
+
if (!fs.existsSync(schemaDir)) {
|
|
76
|
+
throw new Error(`Schema directory not found: ${schemaDir}`);
|
|
77
|
+
}
|
|
78
|
+
registerTsNode();
|
|
79
|
+
(0, decorators_1.clearMetadata)();
|
|
80
|
+
const files = fs.readdirSync(schemaDir).filter((file) => file.endsWith('.ts') && !file.endsWith('.d.ts'));
|
|
81
|
+
if (files.length === 0) {
|
|
82
|
+
throw new Error(`No TypeScript schema files found in ${schemaDir}`);
|
|
83
|
+
}
|
|
84
|
+
const collections = [];
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
const fullPath = path.resolve(schemaDir, file);
|
|
87
|
+
delete require.cache[fullPath];
|
|
88
|
+
const jsPath = fullPath.replace(/\.ts$/, '.js');
|
|
89
|
+
if (fs.existsSync(jsPath)) {
|
|
90
|
+
delete require.cache[jsPath];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const file of files) {
|
|
94
|
+
const fullPath = path.resolve(schemaDir, file);
|
|
95
|
+
try {
|
|
96
|
+
if (tsNodeAvailable) {
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
98
|
+
require(fullPath);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const jsPath = fullPath.replace(/\.ts$/, '.js');
|
|
102
|
+
if (fs.existsSync(jsPath)) {
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
104
|
+
require(jsPath);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw new Error(`Cannot load ${file}: ts-node not available and no compiled .js file found`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const err = error;
|
|
113
|
+
console.warn(`Warning: Failed to load ${file}: ${err.message || 'Unknown error'}`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const collectionMeta = (0, decorators_1.getCollectionMetadata)();
|
|
118
|
+
for (const [className, collectionInfo] of collectionMeta.entries()) {
|
|
119
|
+
let classConstructor = null;
|
|
120
|
+
for (const file of files) {
|
|
121
|
+
const fullPath = path.resolve(schemaDir, file);
|
|
122
|
+
try {
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
124
|
+
const cached = require.cache[fullPath] || require.cache[fullPath.replace(/\.ts$/, '.js')];
|
|
125
|
+
if (cached && cached.exports) {
|
|
126
|
+
if (cached.exports[className]) {
|
|
127
|
+
classConstructor = cached.exports[className];
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (cached.exports.default && cached.exports.default.name === className) {
|
|
131
|
+
classConstructor = cached.exports.default;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Continue searching
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!classConstructor) {
|
|
141
|
+
console.warn(`Warning: Could not find class constructor for ${className}`);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const fieldMeta = (0, decorators_1.getFieldMetadata)(classConstructor);
|
|
145
|
+
if (!fieldMeta || fieldMeta.length === 0) {
|
|
146
|
+
console.warn(`Warning: No fields found for collection ${collectionInfo.name}`);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const fields = fieldMeta.map(decorators_1.fieldMetadataToDefinition);
|
|
150
|
+
collections.push({
|
|
151
|
+
name: collectionInfo.name,
|
|
152
|
+
description: collectionInfo.description,
|
|
153
|
+
database: collectionInfo.database,
|
|
154
|
+
config: collectionInfo.config,
|
|
155
|
+
fields,
|
|
156
|
+
className,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return collections;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/schema-decorators/loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,8DAkGC;AAnJD,uCAAyB;AACzB,2CAA6B;AAE7B,6CAAiH;AAEjH,IAAI,eAAe,GAAG,KAAK,CAAC;AAC5B,IAAI,CAAC;IACH,kEAAkE;IAClE,iEAAiE;IACjE,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAClE,eAAe,GAAG,IAAI,CAAC;AACzB,CAAC;AAAC,MAAM,CAAC;IACP,wBAAwB;AAC1B,CAAC;AAYD,SAAS,cAAc;IACrB,IAAI,eAAe,IAAI,CAAE,MAA2C,CAAC,kBAAkB,EAAE,CAAC;QACxF,IAAI,CAAC;YACH,yDAAyD;YACzD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;YACrF,iEAAiE;YACjE,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;YACnC,MAAM,CAAC,QAAQ,CAAC;gBACd,aAAa,EAAE,IAAI;gBACnB,eAAe,EAAE;oBACf,MAAM,EAAE,UAAU;oBA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AAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Validator for CortexDB TypeScript Schemas
|
|
3
|
+
*
|
|
4
|
+
* Validates relationships and schema consistency, similar to Prisma's validation.
|
|
5
|
+
*/
|
|
6
|
+
import { LoadedCollection } from './loader';
|
|
7
|
+
export interface ValidationError {
|
|
8
|
+
collection: string;
|
|
9
|
+
field?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
suggestion?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ValidationResult {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
errors: ValidationError[];
|
|
16
|
+
warnings: ValidationError[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validate all loaded collections for consistency
|
|
20
|
+
*/
|
|
21
|
+
export declare function validateSchema(collections: LoadedCollection[]): ValidationResult;
|
|
22
|
+
/**
|
|
23
|
+
* Format validation errors for display
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatValidationErrors(result: ValidationResult): string;
|
|
26
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/schema-decorators/validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAiKhF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAkCvE"}
|