ts-prorm-orm 1.1.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.
Files changed (310) hide show
  1. package/CHANGELOG.md +1111 -0
  2. package/LICENSE +21 -0
  3. package/README.md +573 -0
  4. package/dist/audit/history-query.js +180 -0
  5. package/dist/audit/index.js +23 -0
  6. package/dist/audit/logger.js +236 -0
  7. package/dist/cache/cache-manager.js +84 -0
  8. package/dist/cache/index.js +16 -0
  9. package/dist/cache/redis-cluster-cache.js +557 -0
  10. package/dist/cli.js +2200 -0
  11. package/dist/compliance/audit-trail.js +68 -0
  12. package/dist/compliance/backup-verification.js +685 -0
  13. package/dist/compliance/breach-detector.js +505 -0
  14. package/dist/compliance/consent-record.js +227 -0
  15. package/dist/compliance/consent-versioning.js +331 -0
  16. package/dist/compliance/cross-border-log.js +530 -0
  17. package/dist/compliance/data-classifier.js +258 -0
  18. package/dist/compliance/data-lineage.js +565 -0
  19. package/dist/compliance/data-masker.js +303 -0
  20. package/dist/compliance/data-portability.js +265 -0
  21. package/dist/compliance/data-retention.js +195 -0
  22. package/dist/compliance/dsar-workflow.js +342 -0
  23. package/dist/compliance/field-encryption.js +223 -0
  24. package/dist/compliance/immutable-record.js +148 -0
  25. package/dist/compliance/index.js +260 -0
  26. package/dist/compliance/privacy-impact-assessment.js +364 -0
  27. package/dist/compliance/pseudonymization.js +269 -0
  28. package/dist/compliance/query-firewall.js +1182 -0
  29. package/dist/compliance/rate-limiter.js +580 -0
  30. package/dist/compliance/right-to-erasure.js +117 -0
  31. package/dist/compliance/row-level-security.js +246 -0
  32. package/dist/compliance/security-decorator.js +574 -0
  33. package/dist/compliance/security-monitor.js +525 -0
  34. package/dist/compliance/sensitive-data-discovery.js +476 -0
  35. package/dist/compliance/session-isolation.js +472 -0
  36. package/dist/compliance/tls-enforcer.js +108 -0
  37. package/dist/compliance/worm-storage.js +712 -0
  38. package/dist/connection-manager.js +198 -0
  39. package/dist/connection-pool.js +519 -0
  40. package/dist/decorators/audit.js +136 -0
  41. package/dist/decorators/belongs-to-many.js +115 -0
  42. package/dist/decorators/belongs-to.js +115 -0
  43. package/dist/decorators/check.js +435 -0
  44. package/dist/decorators/collate.js +329 -0
  45. package/dist/decorators/comment.js +205 -0
  46. package/dist/decorators/database-settings.js +236 -0
  47. package/dist/decorators/default.js +244 -0
  48. package/dist/decorators/encryption.js +235 -0
  49. package/dist/decorators/engine.js +97 -0
  50. package/dist/decorators/fk-constraints.js +594 -0
  51. package/dist/decorators/foreign-table.js +136 -0
  52. package/dist/decorators/generated.js +274 -0
  53. package/dist/decorators/has-many.js +127 -0
  54. package/dist/decorators/has-one.js +116 -0
  55. package/dist/decorators/hstore.js +129 -0
  56. package/dist/decorators/index.js +355 -0
  57. package/dist/decorators/json-column.js +83 -0
  58. package/dist/decorators/jsonb.js +101 -0
  59. package/dist/decorators/orm-decorators.js +425 -0
  60. package/dist/decorators/permissions.js +294 -0
  61. package/dist/decorators/procedure.js +210 -0
  62. package/dist/decorators/query-options.js +556 -0
  63. package/dist/decorators/range.js +167 -0
  64. package/dist/decorators/set-column.js +83 -0
  65. package/dist/decorators/spatial.js +114 -0
  66. package/dist/decorators/storage.js +580 -0
  67. package/dist/decorators/timezone.js +512 -0
  68. package/dist/decorators/trigger.js +90 -0
  69. package/dist/decorators/uuid.js +135 -0
  70. package/dist/decorators/view.js +258 -0
  71. package/dist/diagrams/chen-diagram.js +354 -0
  72. package/dist/diagrams/class-diagram.js +384 -0
  73. package/dist/diagrams/dependency-diagram.js +432 -0
  74. package/dist/diagrams/er-diagram.js +605 -0
  75. package/dist/diagrams/flow-diagram.js +394 -0
  76. package/dist/diagrams/gantt-diagram.js +411 -0
  77. package/dist/diagrams/index-diagram.js +353 -0
  78. package/dist/diagrams/index.js +184 -0
  79. package/dist/diagrams/migration-diagram.js +316 -0
  80. package/dist/diagrams/model-diagram.js +616 -0
  81. package/dist/diagrams/package-diagram.js +376 -0
  82. package/dist/diagrams/palette.js +85 -0
  83. package/dist/diagrams/relational-diagram.js +455 -0
  84. package/dist/diagrams/schemadoc-diagram.js +309 -0
  85. package/dist/diagrams/sequence-diagram.js +307 -0
  86. package/dist/diagrams/state-diagram.js +344 -0
  87. package/dist/diagrams/svg-dom.js +111 -0
  88. package/dist/diagrams/tree-diagram.js +250 -0
  89. package/dist/dialects/clickhouse/index.js +1742 -0
  90. package/dist/dialects/cockroachdb/index.js +4677 -0
  91. package/dist/dialects/cratedb/index.js +441 -0
  92. package/dist/dialects/databricks/index.js +517 -0
  93. package/dist/dialects/db2/index.js +2225 -0
  94. package/dist/dialects/dialect.js +720 -0
  95. package/dist/dialects/duckdb/index.js +2014 -0
  96. package/dist/dialects/exasol/index.js +357 -0
  97. package/dist/dialects/firebird/index.js +495 -0
  98. package/dist/dialects/greenplum/index.js +457 -0
  99. package/dist/dialects/hana/index.js +1741 -0
  100. package/dist/dialects/mariadb/index.js +3590 -0
  101. package/dist/dialects/mssql/index.js +2296 -0
  102. package/dist/dialects/mysql/index.js +4058 -0
  103. package/dist/dialects/oracle/index.js +2999 -0
  104. package/dist/dialects/postgres/index.js +5319 -0
  105. package/dist/dialects/query-stream-helper.js +152 -0
  106. package/dist/dialects/questdb/index.js +433 -0
  107. package/dist/dialects/redshift/index.js +2277 -0
  108. package/dist/dialects/singlestore/index.js +354 -0
  109. package/dist/dialects/snowflake/index.js +2082 -0
  110. package/dist/dialects/spanner/index.js +1768 -0
  111. package/dist/dialects/sqlite/index.js +3382 -0
  112. package/dist/dialects/tidb/index.js +377 -0
  113. package/dist/dialects/timescaledb/index.js +164 -0
  114. package/dist/dialects/trino/index.js +420 -0
  115. package/dist/dialects/turso/index.js +227 -0
  116. package/dist/dialects/vertica/index.js +317 -0
  117. package/dist/dialects/yugabytedb/index.js +424 -0
  118. package/dist/errors/index.js +472 -0
  119. package/dist/errors/utils.js +340 -0
  120. package/dist/errors.js +21 -0
  121. package/dist/extensions/catalog/cloud-warehouse-features.js +207 -0
  122. package/dist/extensions/catalog/mssql-features.js +147 -0
  123. package/dist/extensions/catalog/mysql-mariadb-plugins.js +229 -0
  124. package/dist/extensions/catalog/oracle-db2-features.js +196 -0
  125. package/dist/extensions/catalog/postgres-extensions.js +516 -0
  126. package/dist/extensions/index.js +71 -0
  127. package/dist/extensions/types.js +13 -0
  128. package/dist/foreign-data.js +173 -0
  129. package/dist/hooks/hooks-manager.js +350 -0
  130. package/dist/hooks/index.js +37 -0
  131. package/dist/index.js +463 -0
  132. package/dist/logging.js +335 -0
  133. package/dist/migrations/index.js +40 -0
  134. package/dist/migrations/migration.js +196 -0
  135. package/dist/migrations/migrator.js +411 -0
  136. package/dist/migrations/prormmigration.js +275 -0
  137. package/dist/migrations/query-interface.js +435 -0
  138. package/dist/migrations/seeder.js +353 -0
  139. package/dist/models/associations.js +852 -0
  140. package/dist/models/constraints.js +288 -0
  141. package/dist/models/data-types.js +2518 -0
  142. package/dist/models/decorators.js +445 -0
  143. package/dist/models/index.js +33 -0
  144. package/dist/models/indexes.js +531 -0
  145. package/dist/models/methods.js +382 -0
  146. package/dist/models/model-manager.js +103 -0
  147. package/dist/models/model.js +5349 -0
  148. package/dist/models/operators.js +67 -0
  149. package/dist/models/scopes.js +189 -0
  150. package/dist/models/typescript-types.js +26 -0
  151. package/dist/nosql/aerospike/index.js +205 -0
  152. package/dist/nosql/allegrograph/index.js +169 -0
  153. package/dist/nosql/arangodb/index.js +364 -0
  154. package/dist/nosql/azure-blob/index.js +206 -0
  155. package/dist/nosql/beanstalkd/index.js +231 -0
  156. package/dist/nosql/beequeue/index.js +210 -0
  157. package/dist/nosql/bigchaindb/index.js +195 -0
  158. package/dist/nosql/bigtable/index.js +224 -0
  159. package/dist/nosql/blazegraph/index.js +173 -0
  160. package/dist/nosql/bullmq/index.js +191 -0
  161. package/dist/nosql/cassandra/index.js +174 -0
  162. package/dist/nosql/chroma/index.js +190 -0
  163. package/dist/nosql/cloudflare-kv/index.js +220 -0
  164. package/dist/nosql/coherence/index.js +200 -0
  165. package/dist/nosql/cosmosdb/index.js +157 -0
  166. package/dist/nosql/couchbase/index.js +213 -0
  167. package/dist/nosql/dax/index.js +212 -0
  168. package/dist/nosql/deno-kv/index.js +206 -0
  169. package/dist/nosql/dgraph/index.js +171 -0
  170. package/dist/nosql/doris/index.js +169 -0
  171. package/dist/nosql/druid/index.js +162 -0
  172. package/dist/nosql/dynamodb/index.js +937 -0
  173. package/dist/nosql/elasticsearch/index.js +377 -0
  174. package/dist/nosql/etcd/index.js +502 -0
  175. package/dist/nosql/eventhubs/index.js +213 -0
  176. package/dist/nosql/eventstore/index.js +254 -0
  177. package/dist/nosql/faunadb/index.js +188 -0
  178. package/dist/nosql/firestore/index.js +177 -0
  179. package/dist/nosql/fluree/index.js +148 -0
  180. package/dist/nosql/fuseki/index.js +170 -0
  181. package/dist/nosql/gcs/index.js +172 -0
  182. package/dist/nosql/gearman/index.js +160 -0
  183. package/dist/nosql/geode/index.js +196 -0
  184. package/dist/nosql/graphdb/index.js +169 -0
  185. package/dist/nosql/graylog/index.js +188 -0
  186. package/dist/nosql/gridgain/index.js +171 -0
  187. package/dist/nosql/hazelcast/index.js +162 -0
  188. package/dist/nosql/hbase/index.js +230 -0
  189. package/dist/nosql/ignite/index.js +173 -0
  190. package/dist/nosql/immudb/index.js +184 -0
  191. package/dist/nosql/index.js +232 -0
  192. package/dist/nosql/infinispan/index.js +200 -0
  193. package/dist/nosql/influxdb/index.js +0 -0
  194. package/dist/nosql/kafka/index.js +234 -0
  195. package/dist/nosql/keyspaces/index.js +189 -0
  196. package/dist/nosql/kinesis/index.js +253 -0
  197. package/dist/nosql/leveldb/index.js +153 -0
  198. package/dist/nosql/lmdb/index.js +160 -0
  199. package/dist/nosql/loki/index.js +201 -0
  200. package/dist/nosql/marklogic/index.js +204 -0
  201. package/dist/nosql/materialize/index.js +145 -0
  202. package/dist/nosql/meilisearch/index.js +154 -0
  203. package/dist/nosql/memcached/index.js +223 -0
  204. package/dist/nosql/milvus/index.js +410 -0
  205. package/dist/nosql/minio/index.js +265 -0
  206. package/dist/nosql/momento/index.js +179 -0
  207. package/dist/nosql/mongodb/index.js +461 -0
  208. package/dist/nosql/nats/index.js +247 -0
  209. package/dist/nosql/nedb/index.js +164 -0
  210. package/dist/nosql/neo4j/index.js +450 -0
  211. package/dist/nosql/neptune/index.js +470 -0
  212. package/dist/nosql/nsq/index.js +200 -0
  213. package/dist/nosql/opensearch/index.js +186 -0
  214. package/dist/nosql/orientdb/index.js +175 -0
  215. package/dist/nosql/papertrail/index.js +200 -0
  216. package/dist/nosql/pinecone/index.js +0 -0
  217. package/dist/nosql/pinot/index.js +133 -0
  218. package/dist/nosql/pouchdb/index.js +172 -0
  219. package/dist/nosql/prometheus/index.js +174 -0
  220. package/dist/nosql/provendb/index.js +147 -0
  221. package/dist/nosql/pubsub/index.js +187 -0
  222. package/dist/nosql/pulsar/index.js +232 -0
  223. package/dist/nosql/qdrant/index.js +295 -0
  224. package/dist/nosql/qldb/index.js +192 -0
  225. package/dist/nosql/r2/index.js +281 -0
  226. package/dist/nosql/rabbitmq/index.js +237 -0
  227. package/dist/nosql/ravendb/index.js +175 -0
  228. package/dist/nosql/redis/index.js +607 -0
  229. package/dist/nosql/redpanda/index.js +237 -0
  230. package/dist/nosql/resque/index.js +203 -0
  231. package/dist/nosql/rethinkdb/index.js +232 -0
  232. package/dist/nosql/rocksdb/index.js +152 -0
  233. package/dist/nosql/rockset/index.js +126 -0
  234. package/dist/nosql/s3/index.js +298 -0
  235. package/dist/nosql/scylladb/index.js +178 -0
  236. package/dist/nosql/signoz/index.js +227 -0
  237. package/dist/nosql/sns/index.js +201 -0
  238. package/dist/nosql/solr/index.js +231 -0
  239. package/dist/nosql/splunk/index.js +227 -0
  240. package/dist/nosql/sqs/index.js +246 -0
  241. package/dist/nosql/stardog/index.js +169 -0
  242. package/dist/nosql/starrocks/index.js +170 -0
  243. package/dist/nosql/store.js +2 -0
  244. package/dist/nosql/sumologic/index.js +213 -0
  245. package/dist/nosql/surrealdb/index.js +179 -0
  246. package/dist/nosql/terminusdb/index.js +151 -0
  247. package/dist/nosql/tigergraph/index.js +469 -0
  248. package/dist/nosql/typesense/index.js +148 -0
  249. package/dist/nosql/unqlite/index.js +157 -0
  250. package/dist/nosql/upstash/index.js +167 -0
  251. package/dist/nosql/vercel-kv/index.js +166 -0
  252. package/dist/nosql/victoriametrics/index.js +213 -0
  253. package/dist/nosql/virtuoso/index.js +169 -0
  254. package/dist/nosql/weaviate/index.js +276 -0
  255. package/dist/operators/index.js +108 -0
  256. package/dist/operators.js +2690 -0
  257. package/dist/prisma-migrate/index.js +38 -0
  258. package/dist/prisma-migrate/migration-generator.js +125 -0
  259. package/dist/prisma-migrate/model-generator.js +172 -0
  260. package/dist/prisma-migrate/relations.js +100 -0
  261. package/dist/prisma-migrate/schema-parser.js +167 -0
  262. package/dist/prisma-migrate/type-mapper.js +40 -0
  263. package/dist/prorm.js +6832 -0
  264. package/dist/query-builders/cte-builder.js +80 -0
  265. package/dist/query-builders/functions/aggregate.js +390 -0
  266. package/dist/query-builders/functions/conditional.js +503 -0
  267. package/dist/query-builders/functions/datetime.js +695 -0
  268. package/dist/query-builders/functions/fulltext.js +439 -0
  269. package/dist/query-builders/functions/index.js +93 -0
  270. package/dist/query-builders/functions/json.js +427 -0
  271. package/dist/query-builders/functions/math.js +399 -0
  272. package/dist/query-builders/functions/string.js +518 -0
  273. package/dist/query-builders/functions/window.js +328 -0
  274. package/dist/query-builders/include-builder.js +323 -0
  275. package/dist/query-builders/index-expression-builder.js +242 -0
  276. package/dist/query-builders/index.js +161 -0
  277. package/dist/query-builders/insert-builder.js +164 -0
  278. package/dist/query-builders/model-helpers.js +38 -0
  279. package/dist/query-builders/order-limit-builder.js +239 -0
  280. package/dist/query-builders/sql-compiler.js +2040 -0
  281. package/dist/query-builders/subquery-builder.js +152 -0
  282. package/dist/query-builders/update-builder.js +182 -0
  283. package/dist/query-builders/view-builder.js +218 -0
  284. package/dist/query-builders/where-builder.js +1532 -0
  285. package/dist/query-interface.js +622 -0
  286. package/dist/query-optimizers/batch-optimizer.js +426 -0
  287. package/dist/query-optimizers/explain-plans.js +415 -0
  288. package/dist/query-optimizers/index.js +51 -0
  289. package/dist/query-optimizers/prepared-statement-cache.js +423 -0
  290. package/dist/query-optimizers/query-hints.js +438 -0
  291. package/dist/query-optimizers/query-optimizer.js +278 -0
  292. package/dist/query-optimizers/slow-query-logger.js +271 -0
  293. package/dist/replica-manager.js +507 -0
  294. package/dist/schema/index.js +15 -0
  295. package/dist/schema/migration-generator.js +374 -0
  296. package/dist/schema/schema-differ.js +549 -0
  297. package/dist/schema/types.js +6 -0
  298. package/dist/sql-constants.js +300 -0
  299. package/dist/sqlite-advanced.js +1047 -0
  300. package/dist/streams/index.js +12 -0
  301. package/dist/streams/transforms.js +178 -0
  302. package/dist/transaction.js +456 -0
  303. package/dist/types/index.js +180 -0
  304. package/dist/user-management.js +127 -0
  305. package/dist/utils/date.js +300 -0
  306. package/dist/utils/index.js +1079 -0
  307. package/dist/utils/string.js +161 -0
  308. package/dist/validators/index.js +19 -0
  309. package/dist/validators/validator.js +911 -0
  310. package/package.json +190 -0
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ /**
3
+ * PackageDiagram — a UML package / namespace grouping diagram.
4
+ *
5
+ * Groups models/tables into packages (schemas, modules, bounded-contexts).
6
+ * Each package is drawn as the classic UML "folder" shape: a small tab rect
7
+ * on the top-left plus a body rect beneath it. Package members are laid out
8
+ * as small labeled boxes in a grid inside the body. Dashed dependency arrows
9
+ * (e.g. «import») connect packages.
10
+ *
11
+ * Each package receives a distinct accent from `rotatedPalettes`; the theme
12
+ * drives the canvas/text colors. Both `color` and `theme` options genuinely
13
+ * change fill/stroke values in the produced SVG, and the viewBox is auto-sized.
14
+ *
15
+ * Usage:
16
+ * const diag = new PackageDiagram({ packages: [...], dependencies: [...] });
17
+ * diag.save('./diagrams/packages.svg');
18
+ * // or:
19
+ * const svgString = diag.generate();
20
+ */
21
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ var desc = Object.getOwnPropertyDescriptor(m, k);
24
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
25
+ desc = { enumerable: true, get: function() { return m[k]; } };
26
+ }
27
+ Object.defineProperty(o, k2, desc);
28
+ }) : (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ o[k2] = m[k];
31
+ }));
32
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
33
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
34
+ }) : function(o, v) {
35
+ o["default"] = v;
36
+ });
37
+ var __importStar = (this && this.__importStar) || (function () {
38
+ var ownKeys = function(o) {
39
+ ownKeys = Object.getOwnPropertyNames || function (o) {
40
+ var ar = [];
41
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
42
+ return ar;
43
+ };
44
+ return ownKeys(o);
45
+ };
46
+ return function (mod) {
47
+ if (mod && mod.__esModule) return mod;
48
+ var result = {};
49
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
50
+ __setModuleDefault(result, mod);
51
+ return result;
52
+ };
53
+ })();
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.PackageDiagram = void 0;
56
+ const fs = __importStar(require("fs"));
57
+ const path = __importStar(require("path"));
58
+ const palette_1 = require("./palette");
59
+ const svg_dom_1 = require("./svg-dom");
60
+ // ─── Main class ─────────────────────────────────────────────────────────────
61
+ class PackageDiagram {
62
+ constructor(options) {
63
+ this.opts = {
64
+ dependencies: options.dependencies ?? [],
65
+ title: options.title ?? '',
66
+ theme: options.theme ?? 'light',
67
+ color: options.color ?? '',
68
+ columns: options.columns ?? 0,
69
+ ...options,
70
+ };
71
+ }
72
+ /** Compute the pixel size of a single package folder. */
73
+ packageSize(pkg) {
74
+ const P = PackageDiagram;
75
+ const memberCount = Math.max(pkg.members.length, 1);
76
+ const cols = Math.min(P.MEMBER_COLS, memberCount);
77
+ const rows = Math.ceil(memberCount / cols);
78
+ const innerW = cols * P.MEMBER_W + (cols - 1) * P.MEMBER_GAP;
79
+ const innerH = rows * P.MEMBER_H + (rows - 1) * P.MEMBER_GAP;
80
+ const w = Math.max(innerW + 2 * P.BODY_PAD, P.TAB_W + 20);
81
+ const h = P.HDR_H + innerH + 2 * P.BODY_PAD;
82
+ return { w, h };
83
+ }
84
+ generate() {
85
+ const P = PackageDiagram;
86
+ const { packages, dependencies, title, theme, color, columns } = this.opts;
87
+ const t = (0, palette_1.resolveTheme)(theme);
88
+ const palettes = (0, palette_1.rotatedPalettes)(color);
89
+ // ── Grid layout of package folders ───────────────────────────────────
90
+ const gridCols = columns > 0 ? columns : Math.ceil(Math.sqrt(Math.max(packages.length, 1)));
91
+ // Measure every package first.
92
+ const sizes = packages.map((p) => this.packageSize(p));
93
+ // Row heights + column widths for a uniform grid.
94
+ const rowCount = Math.ceil(packages.length / gridCols);
95
+ const colWidths = new Array(gridCols).fill(0);
96
+ const rowHeights = new Array(rowCount).fill(0);
97
+ packages.forEach((_, i) => {
98
+ const c = i % gridCols;
99
+ const r = Math.floor(i / gridCols);
100
+ colWidths[c] = Math.max(colWidths[c], sizes[i].w);
101
+ rowHeights[r] = Math.max(rowHeights[r], sizes[i].h);
102
+ });
103
+ const titleH = title ? P.TITLE_H : 0;
104
+ // Cumulative offsets.
105
+ const colX = [];
106
+ let accX = P.PAD;
107
+ for (let c = 0; c < gridCols; c++) {
108
+ colX[c] = accX;
109
+ accX += colWidths[c] + P.GAP_X;
110
+ }
111
+ const rowY = [];
112
+ let accY = P.PAD + titleH + P.TAB_H;
113
+ for (let r = 0; r < rowCount; r++) {
114
+ rowY[r] = accY;
115
+ accY += rowHeights[r] + P.GAP_Y;
116
+ }
117
+ // Place packages, assigning each a rotated accent.
118
+ const placed = packages.map((pkg, i) => {
119
+ const c = i % gridCols;
120
+ const r = Math.floor(i / gridCols);
121
+ const { w, h } = sizes[i];
122
+ return {
123
+ pkg,
124
+ x: colX[c],
125
+ y: rowY[r],
126
+ w,
127
+ h,
128
+ bodyY: rowY[r] + P.TAB_H,
129
+ accent: palettes[i % palettes.length],
130
+ };
131
+ });
132
+ const byName = new Map();
133
+ for (const pl of placed)
134
+ byName.set(pl.pkg.name, pl);
135
+ // ── Canvas size ──────────────────────────────────────────────────────
136
+ const totalW = colX[gridCols - 1] + colWidths[gridCols - 1] + P.PAD;
137
+ const totalH = rowY[rowCount - 1] + rowHeights[rowCount - 1] + P.PAD;
138
+ const doc = new svg_dom_1.SvgDocument(totalW, totalH);
139
+ const svg = doc.root;
140
+ // ── Background ───────────────────────────────────────────────────────
141
+ svg.child('rect', { class: 'canvas', width: totalW, height: totalH, fill: t.canvasBg });
142
+ // ── Arrow marker (in defs) ───────────────────────────────────────────
143
+ const marker = doc.defs().child('marker', {
144
+ id: 'pkgArrow',
145
+ markerWidth: 12,
146
+ markerHeight: 12,
147
+ refX: 9,
148
+ refY: 4,
149
+ orient: 'auto',
150
+ markerUnits: 'userSpaceOnUse',
151
+ });
152
+ marker.child('path', {
153
+ d: 'M0,0 L9,4 L0,8',
154
+ fill: 'none',
155
+ stroke: t.textSecondary,
156
+ 'stroke-width': 1.4,
157
+ });
158
+ // ── Title ────────────────────────────────────────────────────────────
159
+ if (title) {
160
+ svg
161
+ .child('text', {
162
+ class: 'title',
163
+ x: P.PAD,
164
+ y: P.PAD + 26,
165
+ 'font-family': 'system-ui,-apple-system,sans-serif',
166
+ 'font-size': 22,
167
+ 'font-weight': 800,
168
+ fill: t.textPrimary,
169
+ })
170
+ .text(title);
171
+ }
172
+ // ── Dependency arrows (drawn under packages) ─────────────────────────
173
+ for (const dep of dependencies) {
174
+ const a = byName.get(dep.from);
175
+ const b = byName.get(dep.to);
176
+ if (!a || !b)
177
+ continue;
178
+ const [start, end] = this.edgePoints(a, b);
179
+ svg.child('line', {
180
+ class: 'dependency',
181
+ x1: start.x,
182
+ y1: start.y,
183
+ x2: end.x,
184
+ y2: end.y,
185
+ stroke: t.textSecondary,
186
+ 'stroke-width': 1.6,
187
+ 'stroke-dasharray': '7 5',
188
+ 'marker-end': 'url(#pkgArrow)',
189
+ });
190
+ const mx = (start.x + end.x) / 2;
191
+ const my = (start.y + end.y) / 2;
192
+ const label = dep.label ?? '«import»';
193
+ svg
194
+ .child('text', {
195
+ class: 'dependency-label',
196
+ x: mx,
197
+ y: my - 6,
198
+ 'font-family': 'system-ui,sans-serif',
199
+ 'font-size': 11,
200
+ 'font-style': 'italic',
201
+ fill: t.textSecondary,
202
+ 'text-anchor': 'middle',
203
+ })
204
+ .text(label);
205
+ }
206
+ // ── Package folders ──────────────────────────────────────────────────
207
+ for (const pl of placed) {
208
+ this.drawPackage(svg, pl, t);
209
+ }
210
+ return doc.toString('Generated by ts-prorm-orm PackageDiagram');
211
+ }
212
+ /** Compute connection points on the borders of two package boxes. */
213
+ edgePoints(a, b) {
214
+ const ac = { x: a.x + a.w / 2, y: a.bodyY + (a.h) / 2 };
215
+ const bc = { x: b.x + b.w / 2, y: b.bodyY + (b.h) / 2 };
216
+ const clamp = (c, box, toward) => {
217
+ const dx = toward.x - c.x;
218
+ const dy = toward.y - c.y;
219
+ const hw = box.w / 2;
220
+ const hh = box.h / 2;
221
+ if (dx === 0 && dy === 0)
222
+ return c;
223
+ const scaleX = dx !== 0 ? hw / Math.abs(dx) : Infinity;
224
+ const scaleY = dy !== 0 ? hh / Math.abs(dy) : Infinity;
225
+ const s = Math.min(scaleX, scaleY);
226
+ return { x: c.x + dx * s, y: c.y + dy * s };
227
+ };
228
+ return [clamp(ac, a, bc), clamp(bc, b, ac)];
229
+ }
230
+ /** Draw one UML folder-shaped package with its member grid. */
231
+ drawPackage(svg, pl, t) {
232
+ const P = PackageDiagram;
233
+ const { pkg, x, y, w, bodyY, accent } = pl;
234
+ const bodyH = pl.h;
235
+ // Folder tab (top-left small rect).
236
+ svg.child('rect', {
237
+ class: 'package-tab',
238
+ x,
239
+ y,
240
+ width: P.TAB_W,
241
+ height: P.TAB_H,
242
+ rx: 4,
243
+ fill: accent.mid,
244
+ stroke: accent.from,
245
+ 'stroke-width': 1.5,
246
+ });
247
+ // Body rect.
248
+ svg.child('rect', {
249
+ class: 'package-body',
250
+ x,
251
+ y: bodyY,
252
+ width: w,
253
+ height: bodyH,
254
+ rx: 6,
255
+ fill: t.cardBg,
256
+ stroke: accent.from,
257
+ 'stroke-width': 1.8,
258
+ });
259
+ // Header strip inside body (accent tint).
260
+ svg.child('rect', {
261
+ class: 'package-header',
262
+ x,
263
+ y: bodyY,
264
+ width: w,
265
+ height: P.HDR_H,
266
+ rx: 6,
267
+ fill: accent.light,
268
+ });
269
+ // Cover bottom radius of header so it butts the members.
270
+ svg.child('rect', {
271
+ x,
272
+ y: bodyY + P.HDR_H - 6,
273
+ width: w,
274
+ height: 6,
275
+ fill: accent.light,
276
+ });
277
+ svg.child('line', {
278
+ x1: x,
279
+ y1: bodyY + P.HDR_H,
280
+ x2: x + w,
281
+ y2: bodyY + P.HDR_H,
282
+ stroke: accent.from,
283
+ 'stroke-width': 1,
284
+ });
285
+ // Package name (in the tab-aligned header).
286
+ svg
287
+ .child('text', {
288
+ class: 'package-name',
289
+ x: x + P.BODY_PAD,
290
+ y: bodyY + 26,
291
+ 'font-family': 'system-ui,-apple-system,sans-serif',
292
+ 'font-size': 15,
293
+ 'font-weight': 800,
294
+ fill: accent.text,
295
+ })
296
+ .text(pkg.name);
297
+ // Member boxes in a grid.
298
+ const startY = bodyY + P.HDR_H + P.BODY_PAD;
299
+ const startX = x + P.BODY_PAD;
300
+ pkg.members.forEach((m, i) => {
301
+ const c = i % P.MEMBER_COLS;
302
+ const r = Math.floor(i / P.MEMBER_COLS);
303
+ const mx = startX + c * (P.MEMBER_W + P.MEMBER_GAP);
304
+ const my = startY + r * (P.MEMBER_H + P.MEMBER_GAP);
305
+ svg.child('rect', {
306
+ class: 'member',
307
+ x: mx,
308
+ y: my,
309
+ width: P.MEMBER_W,
310
+ height: P.MEMBER_H,
311
+ rx: 5,
312
+ fill: t.rowAlt,
313
+ stroke: accent.mid,
314
+ 'stroke-width': 1,
315
+ });
316
+ // Left accent stripe.
317
+ svg.child('rect', {
318
+ class: 'member-stripe',
319
+ x: mx,
320
+ y: my,
321
+ width: 4,
322
+ height: P.MEMBER_H,
323
+ fill: accent.mid,
324
+ });
325
+ const nameDisp = m.name.length > 18 ? m.name.slice(0, 17) + '…' : m.name;
326
+ svg
327
+ .child('text', {
328
+ class: 'member-name',
329
+ x: mx + 14,
330
+ y: m.kind ? my + 18 : my + 25,
331
+ 'font-family': "'SF Mono','Fira Code',monospace",
332
+ 'font-size': 12,
333
+ 'font-weight': 700,
334
+ fill: t.textPrimary,
335
+ })
336
+ .text(nameDisp);
337
+ if (m.kind) {
338
+ svg
339
+ .child('text', {
340
+ class: 'member-kind',
341
+ x: mx + 14,
342
+ y: my + 32,
343
+ 'font-family': 'system-ui,sans-serif',
344
+ 'font-size': 9,
345
+ fill: t.textSecondary,
346
+ })
347
+ .text(m.kind);
348
+ }
349
+ });
350
+ }
351
+ /**
352
+ * Write the SVG to a file. Creates parent directories if needed.
353
+ */
354
+ save(outputPath) {
355
+ const resolved = path.resolve(outputPath);
356
+ const dir = path.dirname(resolved);
357
+ if (!fs.existsSync(dir))
358
+ fs.mkdirSync(dir, { recursive: true });
359
+ fs.writeFileSync(resolved, this.generate(), 'utf-8');
360
+ return resolved;
361
+ }
362
+ }
363
+ exports.PackageDiagram = PackageDiagram;
364
+ // Layout constants (px)
365
+ PackageDiagram.PAD = 32;
366
+ PackageDiagram.GAP_X = 56;
367
+ PackageDiagram.GAP_Y = 64;
368
+ PackageDiagram.TAB_H = 26;
369
+ PackageDiagram.TAB_W = 120;
370
+ PackageDiagram.HDR_H = 40;
371
+ PackageDiagram.MEMBER_W = 150;
372
+ PackageDiagram.MEMBER_H = 40;
373
+ PackageDiagram.MEMBER_GAP = 12;
374
+ PackageDiagram.BODY_PAD = 16;
375
+ PackageDiagram.MEMBER_COLS = 2;
376
+ PackageDiagram.TITLE_H = 48;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * Shared accent-color and theme resolution for the diagram generators.
4
+ *
5
+ * `--color <name>` (or a custom hex string) picks an accent palette used for
6
+ * header gradients / banners / entity colors.
7
+ * `--theme light|dark` picks a background/text theme.
8
+ *
9
+ * Both are genuinely applied by ModelDiagram, ERDiagram and MigrationDiagram —
10
+ * changing either flag changes real fill/stroke values in the generated SVG.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ACCENT_PALETTES = void 0;
14
+ exports.resolveAccent = resolveAccent;
15
+ exports.rotatedPalettes = rotatedPalettes;
16
+ exports.resolveTheme = resolveTheme;
17
+ // Named palette entries. Order matters: it is also the default cycling order
18
+ // used by ERDiagram when no explicit --color is given.
19
+ exports.ACCENT_PALETTES = [
20
+ { name: 'blue', from: '#1E3A8A', mid: '#2563EB', to: '#60A5FA', light: '#DBEAFE', text: '#1E3A8A' },
21
+ { name: 'violet', from: '#5B21B6', mid: '#7C3AED', to: '#A78BFA', light: '#EDE9FE', text: '#5B21B6' },
22
+ { name: 'emerald', from: '#065F46', mid: '#059669', to: '#34D399', light: '#D1FAE5', text: '#065F46' },
23
+ { name: 'amber', from: '#92400E', mid: '#D97706', to: '#FBBF24', light: '#FEF3C7', text: '#92400E' },
24
+ { name: 'pink', from: '#831843', mid: '#DB2777', to: '#F472B6', light: '#FCE7F3', text: '#831843' },
25
+ { name: 'sky', from: '#0C4A6E', mid: '#0284C7', to: '#38BDF8', light: '#E0F2FE', text: '#0C4A6E' },
26
+ { name: 'indigo', from: '#1E1B4B', mid: '#4338CA', to: '#818CF8', light: '#E0E7FF', text: '#1E1B4B' },
27
+ { name: 'purple', from: '#4A1942', mid: '#9333EA', to: '#C084FC', light: '#F3E8FF', text: '#4A1942' },
28
+ { name: 'red', from: '#7F1D1D', mid: '#DC2626', to: '#F87171', light: '#FEE2E2', text: '#7F1D1D' },
29
+ { name: 'teal', from: '#134E4A', mid: '#0D9488', to: '#2DD4BF', light: '#CCFBF1', text: '#134E4A' },
30
+ { name: 'green', from: '#14532D', mid: '#16A34A', to: '#4ADE80', light: '#DCFCE7', text: '#14532D' },
31
+ { name: 'stone', from: '#1C1917', mid: '#44403C', to: '#A8A29E', light: '#F5F5F4', text: '#1C1917' },
32
+ ];
33
+ const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
34
+ /**
35
+ * Resolve a `--color` flag value to a concrete palette.
36
+ * Accepts a named palette (case-insensitive) or a hex color string.
37
+ * Falls back to the default "blue" palette.
38
+ */
39
+ function resolveAccent(color) {
40
+ if (color) {
41
+ const named = exports.ACCENT_PALETTES.find((p) => p.name === color.toLowerCase());
42
+ if (named)
43
+ return named;
44
+ if (HEX_RE.test(color)) {
45
+ return { name: color, from: color, mid: color, to: color, light: `${color}22`, text: color };
46
+ }
47
+ }
48
+ return exports.ACCENT_PALETTES[0];
49
+ }
50
+ /**
51
+ * Rotate the palette list so it starts at the resolved accent (used by
52
+ * ERDiagram to color multiple entities while still honoring --color for the
53
+ * first/primary entity).
54
+ */
55
+ function rotatedPalettes(color) {
56
+ if (!color)
57
+ return exports.ACCENT_PALETTES;
58
+ const idx = exports.ACCENT_PALETTES.findIndex((p) => p.name === color.toLowerCase());
59
+ if (idx <= 0)
60
+ return exports.ACCENT_PALETTES;
61
+ return [...exports.ACCENT_PALETTES.slice(idx), ...exports.ACCENT_PALETTES.slice(0, idx)];
62
+ }
63
+ const LIGHT_THEME = {
64
+ canvasBg: '#EFF6FF',
65
+ cardBg: '#FFFFFF',
66
+ rowAlt: '#F8FAFC',
67
+ colHeaderBg: '#F1F5F9',
68
+ textPrimary: '#1E293B',
69
+ textSecondary: '#64748B',
70
+ border: '#E2E8F0',
71
+ footerBg: '#1E293B',
72
+ };
73
+ const DARK_THEME = {
74
+ canvasBg: '#0B1120',
75
+ cardBg: '#1E293B',
76
+ rowAlt: '#26374B',
77
+ colHeaderBg: '#111827',
78
+ textPrimary: '#F1F5F9',
79
+ textSecondary: '#94A3B8',
80
+ border: '#334155',
81
+ footerBg: '#020617',
82
+ };
83
+ function resolveTheme(theme) {
84
+ return theme === 'dark' ? DARK_THEME : LIGHT_THEME;
85
+ }