@onroad/core 4.0.0-alpha.15 → 4.0.0-alpha.16
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
CHANGED
|
@@ -930,6 +930,70 @@ export class UserRepository extends BaseRepository<User> {
|
|
|
930
930
|
|
|
931
931
|
---
|
|
932
932
|
|
|
933
|
+
### `import type` with relationship decorators
|
|
934
|
+
|
|
935
|
+
TypeScript's `import type` is erased at compile time. If you use `import type { Foo }` and then reference `Foo` as a **runtime value** inside a decorator like `@HasMany(() => Foo, ...)`, the compiled JavaScript will throw `ReferenceError: Foo is not defined` because the import was stripped.
|
|
936
|
+
|
|
937
|
+
```ts
|
|
938
|
+
// ❌ Wrong — import type is erased, decorator callback fails at runtime
|
|
939
|
+
import type { CampoDeVerificacao } from "./CampoDeVerificacao.js"
|
|
940
|
+
|
|
941
|
+
@Entity("caderno", { engine: "sequelize" })
|
|
942
|
+
export class CadernoDeVerificacao {
|
|
943
|
+
@HasMany(() => CampoDeVerificacao, "cadernoId") // 💥 ReferenceError
|
|
944
|
+
campos!: CampoDeVerificacao[]
|
|
945
|
+
}
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
Fix: use a regular `import` for any class referenced inside a decorator callback:
|
|
949
|
+
|
|
950
|
+
```ts
|
|
951
|
+
// ✅ Correct — regular import keeps the binding at runtime
|
|
952
|
+
import { CampoDeVerificacao } from "./CampoDeVerificacao.js"
|
|
953
|
+
|
|
954
|
+
@Entity("caderno", { engine: "sequelize" })
|
|
955
|
+
export class CadernoDeVerificacao {
|
|
956
|
+
@HasMany(() => CampoDeVerificacao, "cadernoId")
|
|
957
|
+
campos!: CampoDeVerificacao[]
|
|
958
|
+
}
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
> **Tip:** `import type` is safe for type annotations and generics (`extends AbstractService<Foo>`), but never for decorator arguments, `instanceof`, or any expression evaluated at runtime.
|
|
962
|
+
|
|
963
|
+
---
|
|
964
|
+
|
|
965
|
+
### `emitDecoratorMetadata` causes TDZ errors with circular entity imports
|
|
966
|
+
|
|
967
|
+
When `emitDecoratorMetadata: true` is set in `tsconfig.json`, TypeScript emits `__metadata("design:type", CampoDeVerificacao)` for decorated properties. This accesses the imported class **at class definition time**. If two entities import each other (circular dependency), ESM module evaluation order causes a **Temporal Dead Zone (TDZ)** error:
|
|
968
|
+
|
|
969
|
+
```
|
|
970
|
+
ReferenceError: Cannot access 'CampoDeVerificacao' before initialization
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
The `@HasMany(() => Foo, ...)` arrow function is lazy (only called later by `wireSequelizeAssociations`), but `__metadata("design:type", Foo)` is **eager** — it runs during class definition.
|
|
974
|
+
|
|
975
|
+
```jsonc
|
|
976
|
+
// ❌ Wrong — causes TDZ crash in circular ESM imports
|
|
977
|
+
{
|
|
978
|
+
"compilerOptions": {
|
|
979
|
+
"experimentalDecorators": true,
|
|
980
|
+
"emitDecoratorMetadata": true // 💥
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
Fix: disable `emitDecoratorMetadata`. @onroad/core uses only custom metadata keys (`METADATA_KEY.ENTITY`, `ENTITY_COLUMNS`, etc.) and does **not** rely on `design:type`, `design:paramtypes`, or `design:returntype`.
|
|
986
|
+
|
|
987
|
+
```jsonc
|
|
988
|
+
// ✅ Correct — no TDZ, decorators still work
|
|
989
|
+
{
|
|
990
|
+
"compilerOptions": {
|
|
991
|
+
"experimentalDecorators": true,
|
|
992
|
+
"emitDecoratorMetadata": false
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
```
|
|
996
|
+
|
|
933
997
|
---
|
|
934
998
|
|
|
935
999
|
## Migration Guide — Lessons Learned (v3 → v4)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionManager.d.ts","sourceRoot":"","sources":["../../src/database/ConnectionManager.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC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I,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE;QACL,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED,8BAAsB,iBAAiB,CAAC,WAAW;IACjD,SAAS,CAAC,WAAW,2BAAiC;IACtD,SAAS,CAAC,MAAM,EAAE,cAAc,CAAA;gBAEpB,MAAM,EAAE,cAAc;IAIlC,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAEjF,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAElC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAEpD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAS/D,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;CAM3E"}
|
|
@@ -18,7 +18,11 @@ export class ConnectionManager {
|
|
|
18
18
|
resolveDatabaseName(tenant, dataSource) {
|
|
19
19
|
if (this.config.database)
|
|
20
20
|
return this.config.database;
|
|
21
|
-
|
|
21
|
+
if (dataSource)
|
|
22
|
+
return dataSource;
|
|
23
|
+
if (this.config.suffix)
|
|
24
|
+
return `${tenant}_${this.config.suffix}`;
|
|
25
|
+
return `${this.config.prefix}_${tenant}`;
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
//# sourceMappingURL=ConnectionManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionManager.js","sourceRoot":"","sources":["../../src/database/ConnectionManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConnectionManager.js","sourceRoot":"","sources":["../../src/database/ConnectionManager.ts"],"names":[],"mappings":"AAiBA,MAAM,OAAgB,iBAAiB;IAC3B,WAAW,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC5C,MAAM,CAAgB;IAEhC,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAQD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAES,QAAQ,CAAC,MAAc,EAAE,UAAmB;QACpD,0EAA0E;QAC1E,uEAAuE;QACvE,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzB,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAA;QACpF,CAAC;QACD,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,MAAM,CAAA;IACxD,CAAC;IAES,mBAAmB,CAAC,MAAc,EAAE,UAAmB;QAC/D,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAA;QACrD,IAAI,UAAU;YAAE,OAAO,UAAU,CAAA;QACjC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM;YAAE,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;QAChE,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,EAAE,CAAA;IAC1C,CAAC;CACF"}
|
package/package.json
CHANGED