nicot 1.3.7 → 1.4.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/README-CN.md +19 -0
- package/README.md +16 -0
- package/dist/index.cjs +12 -11
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +12 -11
- package/dist/index.mjs.map +2 -2
- package/dist/src/utility/metadata.d.ts +2 -2
- package/index.ts +2 -0
- package/package.json +12 -6
package/README-CN.md
CHANGED
|
@@ -16,6 +16,25 @@ NICOT 是一个 *Entity-Driven* 的全自动 REST 后端框架。
|
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
+
## 测试
|
|
20
|
+
|
|
21
|
+
当前测试默认连接本机 PostgreSQL:
|
|
22
|
+
|
|
23
|
+
- 地址:`localhost:5432`
|
|
24
|
+
- 用户名:`postgres`
|
|
25
|
+
- 密码:`postgres`
|
|
26
|
+
- 数据库:`postgres`
|
|
27
|
+
|
|
28
|
+
可以直接用项目内的测试 compose 启动:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
docker compose -f tests/docker-compose.yml up -d
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
由于 `tests/fulltext.spec.ts` 会使用 `@QueryFullText({ parser: 'zhparser' })`,这里不是普通 `postgres` 镜像,而是带 `zhparser` 扩展的 `zhparser/zhparser:bookworm-16`。
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
19
38
|
## 快速示例
|
|
20
39
|
|
|
21
40
|
```ts
|
package/README.md
CHANGED
|
@@ -52,6 +52,22 @@ NICOT targets:
|
|
|
52
52
|
- NestJS ^9 / ^10 / ^11
|
|
53
53
|
- TypeORM ^0.3.x
|
|
54
54
|
|
|
55
|
+
## Testing
|
|
56
|
+
|
|
57
|
+
The test suite expects PostgreSQL on `localhost:5432` with:
|
|
58
|
+
|
|
59
|
+
- username: `postgres`
|
|
60
|
+
- password: `postgres`
|
|
61
|
+
- database: `postgres`
|
|
62
|
+
|
|
63
|
+
Bring up the test database with:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
docker compose -f tests/docker-compose.yml up -d
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
This project's full-text tests use `@QueryFullText({ parser: 'zhparser' })`, so the test compose uses `zhparser/zhparser:bookworm-16` instead of the plain `postgres` image.
|
|
70
|
+
|
|
55
71
|
---
|
|
56
72
|
|
|
57
73
|
## Quick Start
|
package/dist/index.cjs
CHANGED
|
@@ -90,7 +90,7 @@ var require_typeorm_utils = __commonJS({
|
|
|
90
90
|
throw new circular_dependency_exception_1.CircularDependencyException("@InjectRepository()");
|
|
91
91
|
}
|
|
92
92
|
const dataSourcePrefix = getDataSourcePrefix(dataSource);
|
|
93
|
-
if (entity instanceof Function && (entity.prototype instanceof typeorm_1.Repository || entity.prototype instanceof typeorm_1.AbstractRepository)) {
|
|
93
|
+
if (entity instanceof Function && (entity.prototype instanceof typeorm_1.Repository || typeorm_1.AbstractRepository && entity.prototype instanceof typeorm_1.AbstractRepository)) {
|
|
94
94
|
if (!dataSourcePrefix) {
|
|
95
95
|
return entity;
|
|
96
96
|
}
|
|
@@ -108,7 +108,7 @@ var require_typeorm_utils = __commonJS({
|
|
|
108
108
|
return repository.name;
|
|
109
109
|
}
|
|
110
110
|
function getDataSourceToken(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
111
|
-
return typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource ? typeorm_1.DataSource
|
|
111
|
+
return typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource ? typeorm_1.DataSource : "string" === typeof dataSource ? `${dataSource}DataSource` : typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name ? typeorm_1.DataSource : `${dataSource.name}DataSource`;
|
|
112
112
|
}
|
|
113
113
|
exports2.getConnectionToken = getDataSourceToken;
|
|
114
114
|
function getDataSourcePrefix(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
@@ -313,7 +313,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
313
313
|
typeOrmModuleOptions
|
|
314
314
|
];
|
|
315
315
|
const exports3 = [entityManagerProvider, dataSourceProvider];
|
|
316
|
-
if (dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
316
|
+
if (typeorm_1.Connection && dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
317
317
|
providers.push({
|
|
318
318
|
provide: typeorm_1.Connection,
|
|
319
319
|
useExisting: typeorm_1.DataSource
|
|
@@ -360,7 +360,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
360
360
|
entityManagerProvider,
|
|
361
361
|
dataSourceProvider
|
|
362
362
|
];
|
|
363
|
-
if (dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
363
|
+
if (typeorm_1.Connection && dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
364
364
|
providers.push({
|
|
365
365
|
provide: typeorm_1.Connection,
|
|
366
366
|
useExisting: typeorm_1.DataSource
|
|
@@ -423,9 +423,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
423
423
|
}
|
|
424
424
|
static async createDataSourceFactory(options, dataSourceFactory) {
|
|
425
425
|
const dataSourceToken = (0, typeorm_utils_1.getDataSourceName)(options);
|
|
426
|
-
const createTypeormDataSource = dataSourceFactory ?? ((options2) =>
|
|
427
|
-
return typeorm_1.DataSource === void 0 ? (0, typeorm_1.createConnection)(options2) : new typeorm_1.DataSource(options2);
|
|
428
|
-
});
|
|
426
|
+
const createTypeormDataSource = dataSourceFactory ?? ((options2) => new typeorm_1.DataSource(options2));
|
|
429
427
|
return await (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(async () => {
|
|
430
428
|
let dataSource;
|
|
431
429
|
if (!options.autoLoadEntities) {
|
|
@@ -442,7 +440,7 @@ var require_typeorm_core_module = __commonJS({
|
|
|
442
440
|
entities
|
|
443
441
|
});
|
|
444
442
|
}
|
|
445
|
-
return
|
|
443
|
+
return !dataSource.isInitialized && !options.manualInitialization ? dataSource.initialize() : dataSource;
|
|
446
444
|
}).pipe((0, typeorm_utils_1.handleRetry)(options.retryAttempts, options.retryDelay, dataSourceToken, options.verboseRetryLog, options.toRetry)));
|
|
447
445
|
}
|
|
448
446
|
};
|
|
@@ -674,6 +672,7 @@ __export(index_exports, {
|
|
|
674
672
|
getTransactionalRepositoryToken: () => getTransactionalRepositoryToken
|
|
675
673
|
});
|
|
676
674
|
module.exports = __toCommonJS(index_exports);
|
|
675
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
677
676
|
__reExport(index_exports, require("nesties"), module.exports);
|
|
678
677
|
|
|
679
678
|
// src/dto/import-entry.ts
|
|
@@ -1048,7 +1047,8 @@ var FloatColumn = (type, options = {}) => {
|
|
|
1048
1047
|
}
|
|
1049
1048
|
}
|
|
1050
1049
|
return (0, import_nesties4.MergePropertyDecorators)([
|
|
1051
|
-
(0, import_typeorm.Column)(
|
|
1050
|
+
(0, import_typeorm.Column)({
|
|
1051
|
+
type,
|
|
1052
1052
|
default: options.default,
|
|
1053
1053
|
unsigned: options.unsigned,
|
|
1054
1054
|
...columnDecoratorOptions(options)
|
|
@@ -2059,6 +2059,7 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
|
|
|
2059
2059
|
|
|
2060
2060
|
// src/crud-base.ts
|
|
2061
2061
|
var import_p_queue = __toESM(require("p-queue"));
|
|
2062
|
+
var existingEntitySelect = () => ({ id: true, deleteTime: true });
|
|
2062
2063
|
var Relation = (name, options = {}) => {
|
|
2063
2064
|
return { name, inner: false, ...options };
|
|
2064
2065
|
};
|
|
@@ -2264,7 +2265,7 @@ var CrudBase = class {
|
|
|
2264
2265
|
where: {
|
|
2265
2266
|
id: (0, import_typeorm8.In)(chunk)
|
|
2266
2267
|
},
|
|
2267
|
-
select: this.crudOptions.createOrUpdate ? void 0 :
|
|
2268
|
+
select: this.crudOptions.createOrUpdate ? void 0 : existingEntitySelect(),
|
|
2268
2269
|
withDeleted: true
|
|
2269
2270
|
})
|
|
2270
2271
|
)
|
|
@@ -2369,7 +2370,7 @@ var CrudBase = class {
|
|
|
2369
2370
|
if (ent.id != null) {
|
|
2370
2371
|
const existingEnt = await repo.findOne({
|
|
2371
2372
|
where: { id: ent.id },
|
|
2372
|
-
select: this.crudOptions.createOrUpdate ? void 0 :
|
|
2373
|
+
select: this.crudOptions.createOrUpdate ? void 0 : existingEntitySelect(),
|
|
2373
2374
|
withDeleted: true,
|
|
2374
2375
|
lock: {
|
|
2375
2376
|
mode: "pessimistic_write",
|