@celljs/typeorm 4.3.0 → 4.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.md +104 -1
- package/cell.schema.json +63 -0
- package/cell.yml +10 -11
- package/esm/common/typeorm-initializer.js +1 -1
- package/esm/common/typeorm-initializer.js.map +1 -1
- package/esm/common/utils.js +1 -1
- package/esm/common/utils.js.map +1 -1
- package/lib/common/typeorm-initializer.js +1 -1
- package/lib/common/typeorm-initializer.js.map +1 -1
- package/lib/common/utils.js +1 -1
- package/lib/common/utils.js.map +1 -1
- package/lib/node/default-config.spec.js +15 -17
- package/lib/node/default-config.spec.js.map +1 -1
- package/package.json +5 -4
- package/src/common/typeorm-initializer.ts +1 -1
- package/src/common/utils.ts +1 -1
- package/src/node/default-config.spec.ts +19 -20
package/README.md
CHANGED
|
@@ -8,4 +8,107 @@
|
|
|
8
8
|
npm install @celljs/typeorm mysql2
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Database drivers are not dependencies of this package: install the one your data source uses (`mysql2`, `pg`, `better-sqlite3`, …). `mysql2` is an optional peer dependency; when the driver of a configured data source is missing, the application fails at startup with `CELL_TYPEORM_DRIVER_MISSING` and the command that installs it.
|
|
11
|
+
Database drivers are not dependencies of this package: install the one your data source uses (`mysql2`, `pg`, `better-sqlite3`, `sql.js`, …). `mysql2` is an optional peer dependency; when the driver of a configured data source is missing, the application fails at startup with `CELL_TYPEORM_DRIVER_MISSING` and the command that installs it.
|
|
12
|
+
|
|
13
|
+
## Configure the data source
|
|
14
|
+
|
|
15
|
+
`typeorm.ormConfig` is a list of TypeORM `DataSourceOptions` (or one object). The default, from this package's `cell.yml`, reads the environment:
|
|
16
|
+
|
|
17
|
+
| Variable | Default |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `DB_TYPE` | `mysql` |
|
|
20
|
+
| `DB_HOST` | `localhost` |
|
|
21
|
+
| `DB_PORT` | `3306` |
|
|
22
|
+
| `DB_SYNC` | `true` (only `'true'` enables `synchronize`) |
|
|
23
|
+
| `DB_DATABASE` | `test` |
|
|
24
|
+
|
|
25
|
+
Write your own in `cell.yml`; configuration is server-only, so credentials stay on the server:
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
typeorm:
|
|
29
|
+
ormConfig:
|
|
30
|
+
- type: postgres
|
|
31
|
+
host: "${env.DB_HOST ?? 'localhost'}"
|
|
32
|
+
port: "${ (env.DB_PORT ?? 5432) * 1 }"
|
|
33
|
+
username: "${env.DB_USER}"
|
|
34
|
+
password: "${env.DB_PASSWORD}"
|
|
35
|
+
database: app
|
|
36
|
+
synchronize: false
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Override single values per environment with `CELL_TYPEORM__ORM_CONFIG__0__HOST=db.internal`. For tests, `cell.test.yml` can switch to SQLite in memory (`type: sqljs` with the `sql.js` package). The data sources are created when the application starts and destroyed when it stops.
|
|
40
|
+
|
|
41
|
+
## Entities
|
|
42
|
+
|
|
43
|
+
Register the entity classes in the DI module; the `entities` of the data source are filled from them:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// src/node/module.ts
|
|
47
|
+
import './todo-controller';
|
|
48
|
+
import { autoBind } from '@celljs/core';
|
|
49
|
+
import { autoBindEntities } from '@celljs/typeorm';
|
|
50
|
+
import { Todo } from './todo';
|
|
51
|
+
|
|
52
|
+
autoBindEntities({ Todo }); // an object or an array of classes
|
|
53
|
+
export default autoBind();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// src/node/todo.ts
|
|
58
|
+
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
59
|
+
|
|
60
|
+
@Entity()
|
|
61
|
+
export class Todo {
|
|
62
|
+
@PrimaryGeneratedColumn()
|
|
63
|
+
id: number;
|
|
64
|
+
|
|
65
|
+
@Column()
|
|
66
|
+
title: string;
|
|
67
|
+
|
|
68
|
+
@Column({ default: false })
|
|
69
|
+
done: boolean;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Repositories and transactions
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { Body, Controller, Get, Post } from '@celljs/mvc/lib/node';
|
|
77
|
+
import { OrmContext, Transactional } from '@celljs/typeorm/lib/node';
|
|
78
|
+
import { Todo } from './todo';
|
|
79
|
+
|
|
80
|
+
@Controller('todos')
|
|
81
|
+
export class TodoController {
|
|
82
|
+
@Get()
|
|
83
|
+
@Transactional({ readOnly: true })
|
|
84
|
+
list(): Promise<Todo[]> {
|
|
85
|
+
return OrmContext.getRepository(Todo).find({ order: { id: 'ASC' } });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Post()
|
|
89
|
+
@Transactional()
|
|
90
|
+
create(@Body() body: { title: string }): Promise<Todo> {
|
|
91
|
+
return OrmContext.getRepository(Todo).save(Object.assign(new Todo(), { title: body.title }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- `@Transactional()` runs the method in a transaction: committed when it returns, rolled back when it throws. Within it, `OrmContext.getRepository()`, `getTreeRepository()`, `getMongoRepository()` and `getEntityManager()` use the transaction's entity manager, also in the services the method calls.
|
|
97
|
+
- `readOnly: true` uses the data source's manager without a transaction. `isolation` sets the isolation level.
|
|
98
|
+
- `propagation`: `Propagation.Required` (default) joins a transaction that is already active; `Propagation.RequiresNew` always starts one. Pass it together with the data source name: `@Transactional({ name: 'default', propagation: Propagation.RequiresNew })`.
|
|
99
|
+
- It works on any component method and outside of requests (it creates the context it needs).
|
|
100
|
+
|
|
101
|
+
## Several data sources
|
|
102
|
+
|
|
103
|
+
Give each entry of `ormConfig` a `name`; the entry without one is `default`. Then name it everywhere:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
autoBindEntities([AuditLog], 'audit');
|
|
107
|
+
|
|
108
|
+
@Transactional('audit')
|
|
109
|
+
async record() {
|
|
110
|
+
await OrmContext.getRepository(AuditLog, 'audit').save(...);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`DataSourceManager` (`@celljs/typeorm`) gives the TypeORM `DataSource` objects themselves.
|
package/cell.schema.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"properties": {
|
|
4
|
+
"typeorm": {
|
|
5
|
+
"type": "object",
|
|
6
|
+
"description": "TypeORM.",
|
|
7
|
+
"properties": {
|
|
8
|
+
"ormConfig": {
|
|
9
|
+
"type": "array",
|
|
10
|
+
"description": "Data sources.",
|
|
11
|
+
"items": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"description": "TypeORM DataSource options; name defaults to default.",
|
|
14
|
+
"properties": {
|
|
15
|
+
"name": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"type": {
|
|
19
|
+
"type": "string"
|
|
20
|
+
},
|
|
21
|
+
"host": {
|
|
22
|
+
"type": "string"
|
|
23
|
+
},
|
|
24
|
+
"port": {
|
|
25
|
+
"type": "integer"
|
|
26
|
+
},
|
|
27
|
+
"username": {
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"password": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
},
|
|
33
|
+
"database": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"synchronize": {
|
|
37
|
+
"type": "boolean",
|
|
38
|
+
"description": "Create the schema from the entities on startup; not for production data."
|
|
39
|
+
},
|
|
40
|
+
"logging": {
|
|
41
|
+
"anyOf": [
|
|
42
|
+
{
|
|
43
|
+
"type": "boolean"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"type": "string"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"type": "array",
|
|
50
|
+
"items": {
|
|
51
|
+
"type": "string"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"additionalProperties": true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
package/cell.yml
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
database: "${ env.DB_DATABASE ?: 'test' }"
|
|
1
|
+
typeorm:
|
|
2
|
+
ormConfig:
|
|
3
|
+
# The schema types convert the environment variables: DB_PORT=5432 is a number, DB_SYNC=false is false.
|
|
4
|
+
- type: ${env.DB_TYPE ?? 'mysql'}
|
|
5
|
+
host: ${env.DB_HOST ?? 'localhost'}
|
|
6
|
+
port: ${env.DB_PORT ?? 3306}
|
|
7
|
+
synchronize: ${env.DB_SYNC ?? true}
|
|
8
|
+
# username: ${env.DB_USERNAME ?? 'root'}
|
|
9
|
+
# password: ${env.DB_PASSWORD}
|
|
10
|
+
database: ${env.DB_DATABASE ?? 'test'}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm-initializer.js","sourceRoot":"","sources":["../../src/common/typeorm-initializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAe,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxG,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGrC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAAxB;QAEM,gBAAW,GAAG,IAAI,QAAQ,EAAQ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C9B"}
|
package/esm/common/utils.js
CHANGED
|
@@ -38,7 +38,7 @@ export async function toDriverMissingError(error) {
|
|
|
38
38
|
return new CellError({
|
|
39
39
|
code: 'CELL_TYPEORM_DRIVER_MISSING',
|
|
40
40
|
message: `The database driver${driver ? ` ${driver}` : ''} is not installed: ${error.message}`,
|
|
41
|
-
hint: driver ? `Add it to the dependencies of the project: npm install ${driver}` : 'Install the driver package of the database type in
|
|
41
|
+
hint: driver ? `Add it to the dependencies of the project: npm install ${driver}` : 'Install the driver package of the database type in typeorm.ormConfig.',
|
|
42
42
|
cause: error,
|
|
43
43
|
});
|
|
44
44
|
}
|
package/esm/common/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAa;IAC7C,MAAM,iBAAiB,GAAG,aAAa,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,UAAU,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA4B;;IAChE,MAAM,iBAAiB,GAAG,aAAa,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC/D,IAAI,CAAC;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5E,gFAAgF;QAChF,KAA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AC,EAAE,sBAAsB,KAAK,CAAC,OAAO,EAAE;QAC9F,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,0DAA0D,MAAM,EAAE,CAAC,CAAC,CAAC,uEAAuE;QAC3J,KAAK,EAAE,KAAK;KACf,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -46,7 +46,7 @@ let TypeOrmInitializer = class TypeOrmInitializer {
|
|
|
46
46
|
};
|
|
47
47
|
exports.TypeOrmInitializer = TypeOrmInitializer;
|
|
48
48
|
__decorate([
|
|
49
|
-
(0, core_1.Value)('
|
|
49
|
+
(0, core_1.Value)('typeorm'),
|
|
50
50
|
__metadata("design:type", Object)
|
|
51
51
|
], TypeOrmInitializer.prototype, "options", void 0);
|
|
52
52
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm-initializer.js","sourceRoot":"","sources":["../../src/common/typeorm-initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAwG;AACxG,2CAAsD;AACtD,+DAA0D;AAC1D,uDAAmD;AACnD,mCAA4C;AAGrC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAAxB;QAEM,gBAAW,GAAG,IAAI,eAAQ,EAAQ,CAAC;IAmChD,CAAC;IA3BG,KAAK,CAAC,OAAO,CAAC,GAAgB;QAC1B,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACnC,IAAI,OAAc,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3B,OAAO,GAAG,SAAS,CAAC;QACxB,CAAC;aAAM,CAAC;YACJ,SAAS,CAAC,IAAI,GAAG,mCAAuB,CAAC;YACzC,OAAO,GAAG,CAAE,SAAS,CAAE,CAAC;QAC5B,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC3B,MAAM,CAAC,QAAQ,GAAG,gCAAc,CAAC,WAAW,CAAC,MAAM,CAAC,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;QAED,MAAM,IAAA,yBAAiB,EAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,GAAgB;QACnB,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC;QACvD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACnC,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;gBAC3B,UAAU,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC;QACL,CAAC;IACL,CAAC;CAEJ,CAAA;;AAhCsB;IADlB,IAAA,YAAK,EAAC,SAAS,CAAC;;mDACe;AAGb;IADlB,IAAA,gBAAS,EAAC,uCAAiB,CAAC;8BACS,uCAAiB;6DAAC;6BAR/C,kBAAkB;IAD9B,IAAA,gBAAS,EAAC,2BAAoB,CAAC;GACnB,kBAAkB,CAqC9B"}
|
package/lib/common/utils.js
CHANGED
|
@@ -43,7 +43,7 @@ async function toDriverMissingError(error) {
|
|
|
43
43
|
return new CellError({
|
|
44
44
|
code: 'CELL_TYPEORM_DRIVER_MISSING',
|
|
45
45
|
message: `The database driver${driver ? ` ${driver}` : ''} is not installed: ${error.message}`,
|
|
46
|
-
hint: driver ? `Add it to the dependencies of the project: npm install ${driver}` : 'Install the driver package of the database type in
|
|
46
|
+
hint: driver ? `Add it to the dependencies of the project: npm install ${driver}` : 'Install the driver package of the database type in typeorm.ormConfig.',
|
|
47
47
|
cause: error,
|
|
48
48
|
});
|
|
49
49
|
}
|
package/lib/common/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":";;;;;AAAA,uCAA6C;AAE7C,sCAA8C;AAEvC,KAAK,wBAAwB,IAAa;IAC7C,MAAM,iBAAiB,GAAG,oBAAa,CAAC,GAAG,CAAC,0BAAiB,CAAC,CAAC;IAC/D,MAAM,U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,MAAM,GAAG,MAAA,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,0CAAG,CAAC,CAAC,CAAC;IAClE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAClD,OAAO,IAAI,SAAS,CAAC;QACjB,IAAI,EAAE,6BAA6B;QACnC,OAAO,EAAE,sBAAsB,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,sBAAsB,KAAK,CAAC,OAAO,EAAE;QAC9F,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,0DAA0D,MAAM,EAAE,CAAC,CAAC,CAAC,uEAAuE;QAC3J,KAAK,EAAE,KAAK;KACf,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -4,34 +4,32 @@ const bun_test_1 = require("bun:test");
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const js_yaml_1 = require("js-yaml");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
/** The default ormConfig of cell.yml, evaluated the way the server does
|
|
7
|
+
const expression_util_1 = require("@celljs/core/lib/common/el/expression-util");
|
|
8
|
+
const root = (0, path_1.join)(__dirname, '..', '..');
|
|
9
|
+
/** The default ormConfig of cell.yml, evaluated the way the server does: `env` as the environment, converted to the schema types. */
|
|
10
10
|
function defaults(env) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}));
|
|
11
|
+
const config = (0, js_yaml_1.load)((0, fs_1.readFileSync)((0, path_1.join)(root, 'cell.yml'), 'utf8'));
|
|
12
|
+
const schema = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(root, 'cell.schema.json'), 'utf8'));
|
|
13
|
+
const items = schema.properties.typeorm.properties.ormConfig.items.properties;
|
|
14
|
+
const types = Object.fromEntries(Object.entries(items).filter(([, node]) => node.type === 'integer' || node.type === 'boolean').map(([key, node]) => [`typeorm.ormConfig.0.${key}`, node.type]));
|
|
15
|
+
const context = { typeorm: config.typeorm, env: { ...expression_util_1.ExpressionUtil.definedEnv(env), _ignoreEl: true } };
|
|
16
|
+
expression_util_1.ExpressionUtil.evaluateConfiguration(context, { types });
|
|
17
|
+
return context.typeorm.ormConfig[0];
|
|
19
18
|
}
|
|
20
19
|
(0, bun_test_1.describe)('typeorm default configuration', () => {
|
|
21
20
|
(0, bun_test_1.it)('connects to a local MySQL database without environment variables', () => {
|
|
22
21
|
(0, bun_test_1.expect)(defaults({})).toEqual({ type: 'mysql', host: 'localhost', port: 3306, synchronize: true, database: 'test' });
|
|
23
22
|
});
|
|
24
|
-
(0, bun_test_1.it)('takes DB_* variables with the types
|
|
23
|
+
(0, bun_test_1.it)('takes DB_* variables with the types of the schema', () => {
|
|
25
24
|
const env = { DB_TYPE: 'postgres', DB_HOST: 'db.internal', DB_PORT: '5432', DB_SYNC: 'false', DB_DATABASE: 'app' };
|
|
26
25
|
(0, bun_test_1.expect)(defaults(env)).toEqual({ type: 'postgres', host: 'db.internal', port: 5432, synchronize: false, database: 'app' });
|
|
27
26
|
});
|
|
28
|
-
(0, bun_test_1.it)('
|
|
29
|
-
|
|
30
|
-
(0, bun_test_1.expect)(defaults({ DB_SYNC: value }).synchronize).toBe(false);
|
|
31
|
-
}
|
|
27
|
+
(0, bun_test_1.it)('takes true or false for DB_SYNC and names the key of another value', () => {
|
|
28
|
+
(0, bun_test_1.expect)(defaults({ DB_SYNC: 'FALSE' }).synchronize).toBe(false);
|
|
32
29
|
(0, bun_test_1.expect)(defaults({ DB_SYNC: 'true' }).synchronize).toBe(true);
|
|
33
|
-
// An empty variable counts as unset
|
|
30
|
+
// An empty variable counts as unset.
|
|
34
31
|
(0, bun_test_1.expect)(defaults({ DB_SYNC: '' }).synchronize).toBe(true);
|
|
32
|
+
(0, bun_test_1.expect)(() => defaults({ DB_SYNC: 'no' })).toThrow("typeorm.ormConfig.0.synchronize is a boolean, got 'no'.");
|
|
35
33
|
});
|
|
36
34
|
});
|
|
37
35
|
//# sourceMappingURL=default-config.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-config.spec.js","sourceRoot":"","sources":["../../src/node/default-config.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,2BAAkC;AAClC,qCAA+B;AAC/B,+BAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"default-config.spec.js","sourceRoot":"","sources":["../../src/node/default-config.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,2BAAkC;AAClC,qCAA+B;AAC/B,+BAA4B;AAC5B,gFAA4E;AAE5E,MAAM,IAAI,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEzC,qIAAqI;AACrI,SAAS,QAAQ,CAAC,GAA2B;IACzC,MAAM,MAAM,GAAG,IAAA,cAAI,EAAC,IAAA,iBAAY,EAAC,IAAA,WAAI,EAAC,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAQ,CAAC;IACzE,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,IAAA,WAAI,EAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAChF,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,UAA+C,CAAC;IACnH,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC5B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,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AE,EAAC,oEAAoE,EAAE,GAAG,EAAE;QAC1E,IAAA,iBAAM,EAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAA,iBAAM,EAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,qCAAqC;QACrC,IAAA,iBAAM,EAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,IAAA,iBAAM,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,yDAAyD,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/typeorm",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"lib",
|
|
24
24
|
"esm",
|
|
25
25
|
"src",
|
|
26
|
-
"cell.yml"
|
|
26
|
+
"cell.yml",
|
|
27
|
+
"cell.schema.json"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
@@ -32,8 +33,8 @@
|
|
|
32
33
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@celljs/core": "4.
|
|
36
|
-
"@celljs/kit": "4.
|
|
36
|
+
"@celljs/core": "4.4.0",
|
|
37
|
+
"@celljs/kit": "4.4.0",
|
|
37
38
|
"typeorm": "^0.3.31"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
package/src/common/utils.ts
CHANGED
|
@@ -39,7 +39,7 @@ export async function toDriverMissingError(error: unknown): Promise<Error | unde
|
|
|
39
39
|
return new CellError({
|
|
40
40
|
code: 'CELL_TYPEORM_DRIVER_MISSING',
|
|
41
41
|
message: `The database driver${driver ? ` ${driver}` : ''} is not installed: ${error.message}`,
|
|
42
|
-
hint: driver ? `Add it to the dependencies of the project: npm install ${driver}` : 'Install the driver package of the database type in
|
|
42
|
+
hint: driver ? `Add it to the dependencies of the project: npm install ${driver}` : 'Install the driver package of the database type in typeorm.ormConfig.',
|
|
43
43
|
cause: error,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -2,21 +2,21 @@ import { describe, expect, it } from 'bun:test';
|
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
3
|
import { load } from 'js-yaml';
|
|
4
4
|
import { join } from 'path';
|
|
5
|
-
import {
|
|
6
|
-
import { ExpressionEngine } from '@celljs/core/lib/common/el/expression-engine';
|
|
5
|
+
import { ExpressionUtil } from '@celljs/core/lib/common/el/expression-util';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
const root = join(__dirname, '..', '..');
|
|
8
|
+
|
|
9
|
+
/** The default ormConfig of cell.yml, evaluated the way the server does: `env` as the environment, converted to the schema types. */
|
|
9
10
|
function defaults(env: Record<string, string>): Record<string, unknown> {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
);
|
|
11
|
+
const config = load(readFileSync(join(root, 'cell.yml'), 'utf8')) as any;
|
|
12
|
+
const schema = JSON.parse(readFileSync(join(root, 'cell.schema.json'), 'utf8'));
|
|
13
|
+
const items = schema.properties.typeorm.properties.ormConfig.items.properties as Record<string, { type?: string }>;
|
|
14
|
+
const types = Object.fromEntries(
|
|
15
|
+
Object.entries(items).filter(([, node]) => node.type === 'integer' || node.type === 'boolean').map(([key, node]) => [`typeorm.ormConfig.0.${key}`, node.type]),
|
|
16
|
+
) as Record<string, 'integer' | 'boolean'>;
|
|
17
|
+
const context = { typeorm: config.typeorm, env: { ...ExpressionUtil.definedEnv(env), _ignoreEl: true } };
|
|
18
|
+
ExpressionUtil.evaluateConfiguration(context, { types });
|
|
19
|
+
return context.typeorm.ormConfig[0];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
describe('typeorm default configuration', () => {
|
|
@@ -24,17 +24,16 @@ describe('typeorm default configuration', () => {
|
|
|
24
24
|
expect(defaults({})).toEqual({ type: 'mysql', host: 'localhost', port: 3306, synchronize: true, database: 'test' });
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
it('takes DB_* variables with the types
|
|
27
|
+
it('takes DB_* variables with the types of the schema', () => {
|
|
28
28
|
const env = { DB_TYPE: 'postgres', DB_HOST: 'db.internal', DB_PORT: '5432', DB_SYNC: 'false', DB_DATABASE: 'app' };
|
|
29
29
|
expect(defaults(env)).toEqual({ type: 'postgres', host: 'db.internal', port: 5432, synchronize: false, database: 'app' });
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
it('
|
|
33
|
-
|
|
34
|
-
expect(defaults({ DB_SYNC: value }).synchronize).toBe(false);
|
|
35
|
-
}
|
|
32
|
+
it('takes true or false for DB_SYNC and names the key of another value', () => {
|
|
33
|
+
expect(defaults({ DB_SYNC: 'FALSE' }).synchronize).toBe(false);
|
|
36
34
|
expect(defaults({ DB_SYNC: 'true' }).synchronize).toBe(true);
|
|
37
|
-
// An empty variable counts as unset
|
|
35
|
+
// An empty variable counts as unset.
|
|
38
36
|
expect(defaults({ DB_SYNC: '' }).synchronize).toBe(true);
|
|
37
|
+
expect(() => defaults({ DB_SYNC: 'no' })).toThrow("typeorm.ormConfig.0.synchronize is a boolean, got 'no'.");
|
|
39
38
|
});
|
|
40
|
-
});
|
|
39
|
+
});
|