@tstdl/base 0.91.28 → 0.91.30
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/.eslintrc.json +5 -1
- package/{reflection/reflection-data-map.d.ts → data-structures/context-data-map.d.ts} +3 -2
- package/{reflection/reflection-data-map.js → data-structures/context-data-map.js} +13 -6
- package/data-structures/index.d.ts +1 -0
- package/data-structures/index.js +1 -0
- package/examples/orm/drizzle.config.d.ts +2 -0
- package/examples/orm/drizzle.config.js +5 -0
- package/examples/orm/schemas.d.ts +3 -0
- package/examples/orm/schemas.js +4 -0
- package/examples/orm/test.js +10 -0
- package/examples/orm/user.model.d.ts +9 -0
- package/examples/orm/user.model.js +39 -0
- package/key-value-store/index.d.ts +0 -1
- package/key-value-store/index.js +0 -1
- package/key-value-store/key-value.store.d.ts +9 -10
- package/key-value-store/mongo/mongo-key-value.store.js +2 -1
- package/orm/database-schema.d.ts +8 -0
- package/orm/database-schema.js +13 -0
- package/orm/decorators.d.ts +26 -0
- package/orm/decorators.js +21 -2
- package/orm/drizzle/schema-converter.d.ts +19 -0
- package/orm/drizzle/schema-converter.js +116 -0
- package/orm/entity.d.ts +6 -2
- package/orm/entity.js +6 -6
- package/orm/index.d.ts +1 -2
- package/orm/index.js +1 -2
- package/orm/repository.d.ts +27 -24
- package/orm/repository.js +124 -7
- package/orm/schemas/index.d.ts +1 -0
- package/orm/schemas/index.js +1 -0
- package/orm/schemas/uuid.d.ts +11 -0
- package/orm/schemas/uuid.js +16 -0
- package/orm/types.d.ts +20 -7
- package/orm/types.js +3 -5
- package/package.json +6 -3
- package/reflection/registry.d.ts +9 -6
- package/reflection/registry.js +25 -14
- package/schema/decorators/types.d.ts +1 -0
- package/schema/schema.d.ts +1 -1
- package/schema/schemas/number.d.ts +1 -0
- package/schema/schemas/number.js +2 -0
- package/schema/schemas/string.d.ts +1 -1
- package/utils/math.d.ts +11 -1
- package/utils/math.js +28 -0
- package/utils/string/index.d.ts +1 -0
- package/utils/string/index.js +1 -0
- package/utils/string/snake-case.d.ts +1 -0
- package/utils/string/snake-case.js +4 -0
- package/orm/schema-converter.d.ts +0 -99
- package/orm/schema-converter.js +0 -74
- package/orm/schema.d.ts +0 -3
- /package/{orm/schema.js → examples/orm/test.d.ts} +0 -0
package/orm/schema-converter.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { boolean, doublePrecision, integer, pgSchema, text, unique, uuid } from 'drizzle-orm/pg-core';
|
|
11
|
-
import { NotSupportedError } from '../errors/not-supported.error.js';
|
|
12
|
-
import { reflectionRegistry } from '../reflection/registry.js';
|
|
13
|
-
import { Property } from '../schema/index.js';
|
|
14
|
-
import { fromEntries } from '../utils/object/object.js';
|
|
15
|
-
import { assertStringPass, isUndefined } from '../utils/type-guards.js';
|
|
16
|
-
import { Integer } from './types.js';
|
|
17
|
-
export const mySchema = pgSchema('my_schema');
|
|
18
|
-
export const colors = mySchema.enum('colors', ['red', 'green', 'blue']);
|
|
19
|
-
export const mySchemaUsers = mySchema.table('users', {
|
|
20
|
-
id: uuid('id'),
|
|
21
|
-
name: text('name'),
|
|
22
|
-
age: integer(''),
|
|
23
|
-
color: colors('color').default('red'),
|
|
24
|
-
}, (self) => ({
|
|
25
|
-
unq: unique().on(self.age).nullsNotDistinct().nullsNotDistinct()
|
|
26
|
-
}));
|
|
27
|
-
export function getDrizzleSchemaFromType(type) {
|
|
28
|
-
const metadata = reflectionRegistry.getMetadata(type);
|
|
29
|
-
if (isUndefined(metadata)) {
|
|
30
|
-
throw new Error('Type does not have reflection metadata.');
|
|
31
|
-
}
|
|
32
|
-
const entries = [...metadata.properties].map(([property, propertyMetadata]) => [property, getPostgresColumn(assertStringPass(property), propertyMetadata.type)]);
|
|
33
|
-
const schema = mySchema.table(type.entityName, fromEntries(entries));
|
|
34
|
-
return schema;
|
|
35
|
-
}
|
|
36
|
-
function getPostgresColumn(name, type) {
|
|
37
|
-
if (type == String) {
|
|
38
|
-
return text(name);
|
|
39
|
-
}
|
|
40
|
-
if (type == Number) {
|
|
41
|
-
return doublePrecision(name);
|
|
42
|
-
}
|
|
43
|
-
if (type == Boolean) {
|
|
44
|
-
return boolean(name);
|
|
45
|
-
}
|
|
46
|
-
throw new NotSupportedError(`Type ${type.name} not supported`);
|
|
47
|
-
}
|
|
48
|
-
export class Entity2 {
|
|
49
|
-
id;
|
|
50
|
-
}
|
|
51
|
-
__decorate([
|
|
52
|
-
Property(),
|
|
53
|
-
__metadata("design:type", String)
|
|
54
|
-
], Entity2.prototype, "id", void 0);
|
|
55
|
-
export class User extends Entity2 {
|
|
56
|
-
name;
|
|
57
|
-
age;
|
|
58
|
-
hasAge;
|
|
59
|
-
}
|
|
60
|
-
__decorate([
|
|
61
|
-
Property(),
|
|
62
|
-
__metadata("design:type", String)
|
|
63
|
-
], User.prototype, "name", void 0);
|
|
64
|
-
__decorate([
|
|
65
|
-
Integer(),
|
|
66
|
-
__metadata("design:type", Object)
|
|
67
|
-
], User.prototype, "age", void 0);
|
|
68
|
-
__decorate([
|
|
69
|
-
Property(),
|
|
70
|
-
__metadata("design:type", Boolean)
|
|
71
|
-
], User.prototype, "hasAge", void 0);
|
|
72
|
-
const user = getDrizzleSchemaFromType(User);
|
|
73
|
-
const db = null;
|
|
74
|
-
const results = await db.select().from(user);
|
package/orm/schema.d.ts
DELETED
|
File without changes
|