@c9up/atlas 0.1.3 → 0.1.5

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 (150) hide show
  1. package/db.darwin-arm64.node +0 -0
  2. package/db.darwin-x64.node +0 -0
  3. package/db.linux-arm64-gnu.node +0 -0
  4. package/db.linux-x64-gnu.node +0 -0
  5. package/db.win32-x64-msvc.node +0 -0
  6. package/dist/AtlasProvider.d.ts +106 -0
  7. package/dist/AtlasProvider.d.ts.map +1 -0
  8. package/dist/AtlasProvider.js +190 -0
  9. package/dist/AtlasProvider.js.map +1 -0
  10. package/dist/BaseEntity.d.ts +255 -0
  11. package/dist/BaseEntity.d.ts.map +1 -0
  12. package/dist/BaseEntity.js +420 -0
  13. package/dist/BaseEntity.js.map +1 -0
  14. package/dist/BaseRepository.d.ts +175 -0
  15. package/dist/BaseRepository.d.ts.map +1 -0
  16. package/dist/BaseRepository.js +1451 -0
  17. package/dist/BaseRepository.js.map +1 -0
  18. package/dist/ModelQuery.d.ts +338 -0
  19. package/dist/ModelQuery.d.ts.map +1 -0
  20. package/dist/ModelQuery.js +1598 -0
  21. package/dist/ModelQuery.js.map +1 -0
  22. package/dist/Transaction.d.ts +15 -0
  23. package/dist/Transaction.d.ts.map +1 -0
  24. package/dist/Transaction.js +67 -0
  25. package/dist/Transaction.js.map +1 -0
  26. package/dist/adapters/NapiDbAdapter.d.ts +34 -0
  27. package/dist/adapters/NapiDbAdapter.d.ts.map +1 -0
  28. package/dist/adapters/NapiDbAdapter.js +96 -0
  29. package/dist/adapters/NapiDbAdapter.js.map +1 -0
  30. package/dist/config.d.ts +4 -0
  31. package/dist/config.d.ts.map +1 -0
  32. package/dist/config.js +4 -0
  33. package/dist/config.js.map +1 -0
  34. package/dist/configure.d.ts +10 -0
  35. package/dist/configure.d.ts.map +1 -0
  36. package/dist/configure.js +25 -0
  37. package/dist/configure.js.map +1 -0
  38. package/dist/decorators/entity.d.ts +235 -0
  39. package/dist/decorators/entity.d.ts.map +1 -0
  40. package/dist/decorators/entity.js +264 -0
  41. package/dist/decorators/entity.js.map +1 -0
  42. package/dist/decorators/hooks.d.ts +70 -0
  43. package/dist/decorators/hooks.d.ts.map +1 -0
  44. package/dist/decorators/hooks.js +107 -0
  45. package/dist/decorators/hooks.js.map +1 -0
  46. package/dist/decorators/scope.d.ts +35 -0
  47. package/dist/decorators/scope.d.ts.map +1 -0
  48. package/dist/decorators/scope.js +29 -0
  49. package/dist/decorators/scope.js.map +1 -0
  50. package/dist/errors.d.ts +54 -0
  51. package/dist/errors.d.ts.map +1 -0
  52. package/dist/errors.js +82 -0
  53. package/dist/errors.js.map +1 -0
  54. package/dist/index.d.ts +39 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +28 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/naming/NamingStrategy.d.ts +52 -0
  59. package/dist/naming/NamingStrategy.d.ts.map +1 -0
  60. package/dist/naming/NamingStrategy.js +65 -0
  61. package/dist/naming/NamingStrategy.js.map +1 -0
  62. package/dist/query/QueryBuilder.d.ts +95 -0
  63. package/dist/query/QueryBuilder.d.ts.map +1 -0
  64. package/dist/query/QueryBuilder.js +310 -0
  65. package/dist/query/QueryBuilder.js.map +1 -0
  66. package/dist/query/native.d.ts +18 -0
  67. package/dist/query/native.d.ts.map +1 -0
  68. package/dist/query/native.js +49 -0
  69. package/dist/query/native.js.map +1 -0
  70. package/dist/schema/Migration.d.ts +55 -0
  71. package/dist/schema/Migration.d.ts.map +1 -0
  72. package/dist/schema/Migration.js +68 -0
  73. package/dist/schema/Migration.js.map +1 -0
  74. package/dist/schema/MigrationRunner.d.ts +115 -0
  75. package/dist/schema/MigrationRunner.d.ts.map +1 -0
  76. package/dist/schema/MigrationRunner.js +406 -0
  77. package/dist/schema/MigrationRunner.js.map +1 -0
  78. package/dist/schema/Schema.d.ts +22 -0
  79. package/dist/schema/Schema.d.ts.map +1 -0
  80. package/dist/schema/Schema.js +51 -0
  81. package/dist/schema/Schema.js.map +1 -0
  82. package/dist/schema/SchemaBuilder.d.ts +14 -0
  83. package/dist/schema/SchemaBuilder.d.ts.map +1 -0
  84. package/dist/schema/SchemaBuilder.js +13 -0
  85. package/dist/schema/SchemaBuilder.js.map +1 -0
  86. package/dist/schema/Seeder.d.ts +54 -0
  87. package/dist/schema/Seeder.d.ts.map +1 -0
  88. package/dist/schema/Seeder.js +89 -0
  89. package/dist/schema/Seeder.js.map +1 -0
  90. package/dist/schema/TableBuilder.d.ts +95 -0
  91. package/dist/schema/TableBuilder.d.ts.map +1 -0
  92. package/dist/schema/TableBuilder.js +234 -0
  93. package/dist/schema/TableBuilder.js.map +1 -0
  94. package/dist/schema/types.d.ts +30 -0
  95. package/dist/schema/types.d.ts.map +1 -0
  96. package/dist/schema/types.js +19 -0
  97. package/dist/schema/types.js.map +1 -0
  98. package/dist/services/db.d.ts +22 -0
  99. package/dist/services/db.d.ts.map +1 -0
  100. package/dist/services/db.js +37 -0
  101. package/dist/services/db.js.map +1 -0
  102. package/dist/testing/DatabaseCleanup.d.ts +19 -0
  103. package/dist/testing/DatabaseCleanup.d.ts.map +1 -0
  104. package/dist/testing/DatabaseCleanup.js +39 -0
  105. package/dist/testing/DatabaseCleanup.js.map +1 -0
  106. package/dist/testing/Factory.d.ts +59 -0
  107. package/dist/testing/Factory.d.ts.map +1 -0
  108. package/dist/testing/Factory.js +105 -0
  109. package/dist/testing/Factory.js.map +1 -0
  110. package/dist/testing/TestDatabase.d.ts +25 -0
  111. package/dist/testing/TestDatabase.d.ts.map +1 -0
  112. package/dist/testing/TestDatabase.js +52 -0
  113. package/dist/testing/TestDatabase.js.map +1 -0
  114. package/dist/testing/index.d.ts +4 -0
  115. package/dist/testing/index.d.ts.map +1 -0
  116. package/dist/testing/index.js +4 -0
  117. package/dist/testing/index.js.map +1 -0
  118. package/dist/utils/casing.d.ts +5 -0
  119. package/dist/utils/casing.d.ts.map +1 -0
  120. package/dist/utils/casing.js +9 -0
  121. package/dist/utils/casing.js.map +1 -0
  122. package/dist/utils/dialectFromUrl.d.ts +10 -0
  123. package/dist/utils/dialectFromUrl.d.ts.map +1 -0
  124. package/dist/utils/dialectFromUrl.js +8 -0
  125. package/dist/utils/dialectFromUrl.js.map +1 -0
  126. package/dist/utils/identifier.d.ts +19 -0
  127. package/dist/utils/identifier.d.ts.map +1 -0
  128. package/dist/utils/identifier.js +27 -0
  129. package/dist/utils/identifier.js.map +1 -0
  130. package/dist/utils/safePath.d.ts +22 -0
  131. package/dist/utils/safePath.d.ts.map +1 -0
  132. package/dist/utils/safePath.js +46 -0
  133. package/dist/utils/safePath.js.map +1 -0
  134. package/dist/utils/transactionBrand.d.ts +5 -0
  135. package/dist/utils/transactionBrand.d.ts.map +1 -0
  136. package/dist/utils/transactionBrand.js +5 -0
  137. package/dist/utils/transactionBrand.js.map +1 -0
  138. package/index.darwin-arm64.node +0 -0
  139. package/index.darwin-x64.node +0 -0
  140. package/index.linux-arm64-gnu.node +0 -0
  141. package/index.linux-x64-gnu.node +0 -0
  142. package/index.win32-x64-msvc.node +0 -0
  143. package/package.json +1 -1
  144. package/src/AtlasProvider.ts +2 -2
  145. package/src/BaseRepository.ts +73 -11
  146. package/src/adapters/NapiDbAdapter.ts +1 -1
  147. package/src/schema/MigrationRunner.ts +16 -12
  148. package/src/schema/TableBuilder.ts +26 -0
  149. package/src/schema/types.ts +2 -0
  150. package/src/testing/DatabaseCleanup.ts +6 -7
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Seeder — populate the database with default / reference / test data.
3
+ *
4
+ * The canonical pattern:
5
+ *
6
+ * export default class CountrySeeder extends BaseSeeder {
7
+ * async run() {
8
+ * // Idempotent via updateOrCreateMany — safe to re-run.
9
+ * await Country.updateOrCreateMany('isoCode', [
10
+ * { isoCode: 'FR', name: 'France' },
11
+ * { isoCode: 'IN', name: 'India' },
12
+ * ])
13
+ * }
14
+ * }
15
+ *
16
+ * @implements MISS-4, Story 32.12
17
+ */
18
+ import * as fsp from "node:fs/promises";
19
+ import { pathToFileURL } from "node:url";
20
+ import { AtlasError } from "../errors.js";
21
+ import { assertPathInsideBase, assertSafeName, pathExists, } from "../utils/safePath.js";
22
+ /**
23
+ * Base class for all seeders.
24
+ *
25
+ * Subclasses receive the database connection via the constructor so they can
26
+ * build repositories inside `run()` without resorting to globals.
27
+ */
28
+ export class BaseSeeder {
29
+ db;
30
+ constructor(db) {
31
+ this.db = db;
32
+ }
33
+ }
34
+ /** Legacy alias kept for code using the previous API. */
35
+ export const Seeder = BaseSeeder;
36
+ /**
37
+ * Run a pre-built list of seeder INSTANCES in order. Each `run()` is awaited
38
+ * sequentially so ordering is deterministic and side effects are visible to
39
+ * subsequent seeders.
40
+ */
41
+ export async function runSeeders(seeders, _db) {
42
+ for (const seeder of seeders) {
43
+ await seeder.run();
44
+ }
45
+ }
46
+ /**
47
+ * Discover seeder files under `dir`, import them in alphabetical order, build
48
+ * instances with the given DB connection, and run them sequentially.
49
+ *
50
+ * Usage: `await runSeederDirectory('./database/seeders', db)`
51
+ *
52
+ * @param dir Directory containing `.ts` / `.js` seeder files
53
+ * @param db Database connection passed to each seeder constructor
54
+ * @param options Optional filter (`files: ['CountrySeeder']`) to run a subset
55
+ *
56
+ * @implements Story 32.12
57
+ */
58
+ export async function runSeederDirectory(dir, db, options) {
59
+ if (!(await pathExists(dir))) {
60
+ throw new AtlasError("E_SEEDER_DIR_NOT_FOUND", `Seeder directory not found: ${dir}`, {
61
+ hint: "Create the directory or adjust the path passed to runSeederDirectory.",
62
+ });
63
+ }
64
+ const allFiles = (await fsp.readdir(dir))
65
+ .filter((f) => (f.endsWith(".ts") || f.endsWith(".js")) && !f.endsWith(".d.ts"))
66
+ .sort();
67
+ const selected = options?.files
68
+ ? allFiles.filter((f) => options.files?.includes(f.replace(/\.(ts|js)$/, "")))
69
+ : allFiles;
70
+ const executed = [];
71
+ for (const file of selected) {
72
+ assertSafeName(file, "E_SEEDER_INVALID", "seeder");
73
+ const resolved = assertPathInsideBase(dir, file, "E_SEEDER_INVALID_PATH", "Seeder");
74
+ // `pathToFileURL` is required on Windows where bare `C:\…` paths
75
+ // trip ESM's ERR_UNSUPPORTED_ESM_URL_SCHEME on dynamic import.
76
+ const mod = await import(pathToFileURL(resolved).href);
77
+ const SeederClass = mod.default;
78
+ if (!SeederClass || typeof SeederClass !== "function") {
79
+ throw new AtlasError("E_SEEDER_INVALID", `Seeder ${file} must export a default class extending BaseSeeder`, {
80
+ hint: "Example: `export default class UserSeeder extends BaseSeeder { async run() { ... } }`",
81
+ });
82
+ }
83
+ const instance = new SeederClass(db);
84
+ await instance.run();
85
+ executed.push(file.replace(/\.(ts|js)$/, ""));
86
+ }
87
+ return executed;
88
+ }
89
+ //# sourceMappingURL=Seeder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Seeder.js","sourceRoot":"","sources":["../../src/schema/Seeder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,UAAU,GACV,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,OAAgB,UAAU;IACrB,EAAE,CAAqB;IAEjC,YAAY,EAAsB;QACjC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;CAID;AAED,yDAAyD;AACzD,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC;AAEjC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC/B,OAAqB,EACrB,GAAwB;IAExB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;AACF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,M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,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;YACvD,MAAM,IAAI,UAAU,CACnB,kBAAkB,EAClB,UAAU,IAAI,mDAAmD,EACjE;gBACC,IAAI,EAAE,uFAAuF;aAC7F,CACD,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAe,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;QACjD,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * TableBuilder — fluent column/index builder used inside `Schema.createTable()`.
3
+ *
4
+ * Builds an in-memory column/index spec, then delegates SQL generation to the
5
+ * Rust compiler via `compileStatementNative`. No SQL strings are produced in TS.
6
+ *
7
+ * @implements FR34
8
+ */
9
+ import { type AtlasDialect } from "../query/native.js";
10
+ import { type ColumnDefinition, type IndexDefinition } from "./types.js";
11
+ /** Table builder — used inside `schema.createTable(name, callback)`. */
12
+ export declare class TableBuilder {
13
+ #private;
14
+ readonly tableName: string;
15
+ constructor(tableName: string);
16
+ uuid(name: string): this;
17
+ /**
18
+ * Auto-incrementing integer primary key (Lucid `increments()`). The Rust
19
+ * compiler emits the dialect-appropriate identity clause (SQLite
20
+ * `AUTOINCREMENT`, Postgres `GENERATED ... AS IDENTITY`, MySQL
21
+ * `AUTO_INCREMENT`). For a 64-bit key use `bigIncrements()`.
22
+ */
23
+ increments(name?: string): this;
24
+ /** Auto-incrementing 64-bit primary key (Lucid `bigIncrements()`). */
25
+ bigIncrements(name?: string): this;
26
+ string(name: string, length?: number): this;
27
+ text(name: string): this;
28
+ integer(name: string): this;
29
+ bigInteger(name: string): this;
30
+ decimal(name: string, precision?: number, scale?: number): this;
31
+ boolean(name: string): this;
32
+ date(name: string): this;
33
+ timestamp(name: string): this;
34
+ json(name: string): this;
35
+ binary(name: string): this;
36
+ /**
37
+ * UUID primary key with Postgres-only `gen_random_uuid()` default.
38
+ *
39
+ * **Portability warning — DO NOT use in framework-shipped migration templates.**
40
+ *
41
+ * `gen_random_uuid()` is a Postgres-13+ built-in. SQLite and MySQL do NOT
42
+ * provide a function by that name; calling `id()` in a migration that
43
+ * runs on those dialects fails at `migrations:run` with a "no such
44
+ * function" error. The helper is retained for user-app migrations where
45
+ * the target dialect is known to be Postgres.
46
+ *
47
+ * In framework-shipped templates, write the column explicitly and supply
48
+ * the UUID at INSERT time:
49
+ *
50
+ * t.uuid('id').primary() // no DEFAULT
51
+ * // and at insert: db.insert({ id: crypto.randomUUID(), ... })
52
+ *
53
+ * See `AUDIT-migration-templates.md` (shipped at the package root) for
54
+ * the full audit and the escape-hatch procedure if a future story makes
55
+ * the helper dialect-aware.
56
+ */
57
+ id(): this;
58
+ /**
59
+ * `created_at` + `updated_at` columns with Postgres-only `DEFAULT NOW()`.
60
+ *
61
+ * **Portability warning — DO NOT use in framework-shipped migration templates.**
62
+ *
63
+ * `NOW()` is a Postgres/MySQL function — SQLite does NOT recognise it
64
+ * (SQLite accepts `CURRENT_TIMESTAMP`, not `NOW()`). Calling
65
+ * `timestamps()` in a migration that runs on SQLite fails at
66
+ * `migrations:run` with a "no such function" error. The helper is
67
+ * retained for user-app migrations where the target dialect is known to
68
+ * be Postgres or MySQL.
69
+ *
70
+ * In framework-shipped templates, write the columns explicitly without a
71
+ * DEFAULT and supply the value at INSERT/UPSERT time:
72
+ *
73
+ * t.timestamp('created_at').notNullable() // no DEFAULT
74
+ * t.timestamp('updated_at').notNullable()
75
+ * // and at insert: db.insert({ created_at: new Date().toISOString(), ... })
76
+ *
77
+ * See `AUDIT-migration-templates.md` (shipped at the package root) for
78
+ * the full audit and the escape-hatch procedure if a future story makes
79
+ * the helper dialect-aware.
80
+ */
81
+ timestamps(): this;
82
+ primary(): this;
83
+ notNullable(): this;
84
+ nullable(): this;
85
+ unique(): this;
86
+ defaultTo(value: string): this;
87
+ references(table: string, column?: string): this;
88
+ index(columns: string | string[], name?: string): this;
89
+ uniqueIndex(columns: string | string[], name?: string): this;
90
+ getColumns(): ColumnDefinition[];
91
+ getIndexes(): IndexDefinition[];
92
+ /** Compile to SQL statements via the Rust compiler. */
93
+ toStatements(dialect?: AtlasDialect): string[];
94
+ }
95
+ //# sourceMappingURL=TableBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableBuilder.d.ts","sourceRoot":"","sources":["../../src/schema/TableBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,KAAK,YAAY,EAGjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,eAAe,EAEpB,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,qBAAa,YAAY;;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAKf,SAAS,EAAE,MAAM;IAM7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB;;;;;OAKG;IACH,UAAU,CAAC,IAAI,SAAO,GAAG,IAAI;IAI7B,sEAAsE;IACtE,aAAa,CAAC,IAAI,SAAO,GAAG,IAAI;IAIhC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAM,GAAG,IAAI;IAMxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAGxB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAG3B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI9B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAK,EAAE,KAAK,SAAI,GAAG,IAAI;IAStD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAG3B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAGxB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAG7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAGxB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,EAAE,IAAI,IAAI;IAIV;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,UAAU,IAAI,IAAI;IAQlB,OAAO,IAAI,IAAI;IAKf,WAAW,IAAI,IAAI;IAKnB,QAAQ,IAAI,IAAI;IAKhB,MAAM,IAAI,IAAI;IAKd,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK9B,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,IAAI;IAO9C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAUtD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAY5D,UAAU,IAAI,gBAAgB,EAAE;IAGhC,UAAU,IAAI,eAAe,EAAE;IAI/B,uDAAuD;IACvD,YAAY,CAAC,OAAO,GAAE,YAAgC,GAAG,MAAM,EAAE;CAiDjE"}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * TableBuilder — fluent column/index builder used inside `Schema.createTable()`.
3
+ *
4
+ * Builds an in-memory column/index spec, then delegates SQL generation to the
5
+ * Rust compiler via `compileStatementNative`. No SQL strings are produced in TS.
6
+ *
7
+ * @implements FR34
8
+ */
9
+ import { compileStatementNative, getAtlasDialect, } from "../query/native.js";
10
+ import { TYPE_KIND_MAP, } from "./types.js";
11
+ /** Table builder — used inside `schema.createTable(name, callback)`. */
12
+ export class TableBuilder {
13
+ tableName;
14
+ #columns = [];
15
+ #indexes = [];
16
+ #currentColumn;
17
+ constructor(tableName) {
18
+ this.tableName = tableName;
19
+ }
20
+ // ─── Column types ─────────────────────────────────────────
21
+ uuid(name) {
22
+ return this.#addColumn(name, "uuid");
23
+ }
24
+ /**
25
+ * Auto-incrementing integer primary key (Lucid `increments()`). The Rust
26
+ * compiler emits the dialect-appropriate identity clause (SQLite
27
+ * `AUTOINCREMENT`, Postgres `GENERATED ... AS IDENTITY`, MySQL
28
+ * `AUTO_INCREMENT`). For a 64-bit key use `bigIncrements()`.
29
+ */
30
+ increments(name = "id") {
31
+ return this.#addIncrements(name, "integer");
32
+ }
33
+ /** Auto-incrementing 64-bit primary key (Lucid `bigIncrements()`). */
34
+ bigIncrements(name = "id") {
35
+ return this.#addIncrements(name, "bigInteger");
36
+ }
37
+ string(name, length = 255) {
38
+ this.#addColumn(name, "string");
39
+ if (this.#currentColumn)
40
+ this.#currentColumn.length = length;
41
+ return this;
42
+ }
43
+ text(name) {
44
+ return this.#addColumn(name, "text");
45
+ }
46
+ integer(name) {
47
+ return this.#addColumn(name, "integer");
48
+ }
49
+ bigInteger(name) {
50
+ return this.#addColumn(name, "bigInteger");
51
+ }
52
+ decimal(name, precision = 10, scale = 2) {
53
+ this.#addColumn(name, "decimal");
54
+ if (this.#currentColumn) {
55
+ this.#currentColumn.precision = precision;
56
+ this.#currentColumn.scale = scale;
57
+ }
58
+ return this;
59
+ }
60
+ boolean(name) {
61
+ return this.#addColumn(name, "boolean");
62
+ }
63
+ date(name) {
64
+ return this.#addColumn(name, "date");
65
+ }
66
+ timestamp(name) {
67
+ return this.#addColumn(name, "timestamp");
68
+ }
69
+ json(name) {
70
+ return this.#addColumn(name, "json");
71
+ }
72
+ binary(name) {
73
+ return this.#addColumn(name, "binary");
74
+ }
75
+ // ─── Shortcuts ────────────────────────────────────────────
76
+ /**
77
+ * UUID primary key with Postgres-only `gen_random_uuid()` default.
78
+ *
79
+ * **Portability warning — DO NOT use in framework-shipped migration templates.**
80
+ *
81
+ * `gen_random_uuid()` is a Postgres-13+ built-in. SQLite and MySQL do NOT
82
+ * provide a function by that name; calling `id()` in a migration that
83
+ * runs on those dialects fails at `migrations:run` with a "no such
84
+ * function" error. The helper is retained for user-app migrations where
85
+ * the target dialect is known to be Postgres.
86
+ *
87
+ * In framework-shipped templates, write the column explicitly and supply
88
+ * the UUID at INSERT time:
89
+ *
90
+ * t.uuid('id').primary() // no DEFAULT
91
+ * // and at insert: db.insert({ id: crypto.randomUUID(), ... })
92
+ *
93
+ * See `AUDIT-migration-templates.md` (shipped at the package root) for
94
+ * the full audit and the escape-hatch procedure if a future story makes
95
+ * the helper dialect-aware.
96
+ */
97
+ id() {
98
+ return this.uuid("id").primary().defaultTo("gen_random_uuid()");
99
+ }
100
+ /**
101
+ * `created_at` + `updated_at` columns with Postgres-only `DEFAULT NOW()`.
102
+ *
103
+ * **Portability warning — DO NOT use in framework-shipped migration templates.**
104
+ *
105
+ * `NOW()` is a Postgres/MySQL function — SQLite does NOT recognise it
106
+ * (SQLite accepts `CURRENT_TIMESTAMP`, not `NOW()`). Calling
107
+ * `timestamps()` in a migration that runs on SQLite fails at
108
+ * `migrations:run` with a "no such function" error. The helper is
109
+ * retained for user-app migrations where the target dialect is known to
110
+ * be Postgres or MySQL.
111
+ *
112
+ * In framework-shipped templates, write the columns explicitly without a
113
+ * DEFAULT and supply the value at INSERT/UPSERT time:
114
+ *
115
+ * t.timestamp('created_at').notNullable() // no DEFAULT
116
+ * t.timestamp('updated_at').notNullable()
117
+ * // and at insert: db.insert({ created_at: new Date().toISOString(), ... })
118
+ *
119
+ * See `AUDIT-migration-templates.md` (shipped at the package root) for
120
+ * the full audit and the escape-hatch procedure if a future story makes
121
+ * the helper dialect-aware.
122
+ */
123
+ timestamps() {
124
+ this.timestamp("created_at").notNullable().defaultTo("NOW()");
125
+ this.timestamp("updated_at").notNullable().defaultTo("NOW()");
126
+ return this;
127
+ }
128
+ // ─── Column modifiers ─────────────────────────────────────
129
+ primary() {
130
+ if (this.#currentColumn)
131
+ this.#currentColumn.primary = true;
132
+ return this;
133
+ }
134
+ notNullable() {
135
+ if (this.#currentColumn)
136
+ this.#currentColumn.nullable = false;
137
+ return this;
138
+ }
139
+ nullable() {
140
+ if (this.#currentColumn)
141
+ this.#currentColumn.nullable = true;
142
+ return this;
143
+ }
144
+ unique() {
145
+ if (this.#currentColumn)
146
+ this.#currentColumn.unique = true;
147
+ return this;
148
+ }
149
+ defaultTo(value) {
150
+ if (this.#currentColumn)
151
+ this.#currentColumn.defaultValue = value;
152
+ return this;
153
+ }
154
+ references(table, column = "id") {
155
+ if (this.#currentColumn)
156
+ this.#currentColumn.references = { table, column };
157
+ return this;
158
+ }
159
+ // ─── Indexes ──────────────────────────────────────────────
160
+ index(columns, name) {
161
+ const cols = Array.isArray(columns) ? columns : [columns];
162
+ this.#indexes.push({
163
+ name: name ?? `idx_${this.tableName}_${cols.join("_")}`,
164
+ columns: cols,
165
+ unique: false,
166
+ });
167
+ return this;
168
+ }
169
+ uniqueIndex(columns, name) {
170
+ const cols = Array.isArray(columns) ? columns : [columns];
171
+ this.#indexes.push({
172
+ name: name ?? `idx_${this.tableName}_${cols.join("_")}_unique`,
173
+ columns: cols,
174
+ unique: true,
175
+ });
176
+ return this;
177
+ }
178
+ // ─── Accessors ────────────────────────────────────────────
179
+ getColumns() {
180
+ return [...this.#columns];
181
+ }
182
+ getIndexes() {
183
+ return [...this.#indexes];
184
+ }
185
+ /** Compile to SQL statements via the Rust compiler. */
186
+ toStatements(dialect = getAtlasDialect()) {
187
+ const spec = {
188
+ kind: "createTable",
189
+ table: this.tableName,
190
+ columns: this.#columns.map((c) => ({
191
+ name: c.name,
192
+ kind: TYPE_KIND_MAP[c.type],
193
+ length: c.length ?? null,
194
+ precision: c.precision ?? null,
195
+ scale: c.scale ?? null,
196
+ nullable: c.nullable,
197
+ primary: c.primary,
198
+ autoIncrement: c.autoIncrement ?? false,
199
+ unique: c.unique,
200
+ default: c.defaultValue ?? null,
201
+ references: c.references ?? null,
202
+ })),
203
+ indexes: this.#indexes.map((i) => ({
204
+ name: i.name,
205
+ columns: i.columns,
206
+ unique: i.unique,
207
+ })),
208
+ ifNotExists: false,
209
+ };
210
+ return compileStatementNative(spec, dialect).statements;
211
+ }
212
+ #addColumn(name, type) {
213
+ const col = {
214
+ name,
215
+ type,
216
+ nullable: true,
217
+ primary: false,
218
+ unique: false,
219
+ };
220
+ this.#columns.push(col);
221
+ this.#currentColumn = col;
222
+ return this;
223
+ }
224
+ #addIncrements(name, type) {
225
+ this.#addColumn(name, type);
226
+ if (this.#currentColumn) {
227
+ this.#currentColumn.autoIncrement = true;
228
+ this.#currentColumn.primary = true;
229
+ this.#currentColumn.nullable = false;
230
+ }
231
+ return this;
232
+ }
233
+ }
234
+ //# sourceMappingURL=TableBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableBuilder.js","sourceRoot":"","sources":["../../src/schema/TableBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEN,sBAAsB,EACtB,eAAe,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAIN,aAAa,GACb,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,MAAM,OAAO,YAAY;IACf,SAAS,CAAS;IAC3B,QAAQ,GAAuB,EAAE,CAAC;IAClC,QAAQ,GAAsB,EAAE,CAAC;IACjC,cAAc,CAAoB;IAElC,YAAY,SAAiB;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,6DAA6D;IAE7D,IAAI,CAAC,IAAY;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,IAAI,GAAG,IAAI;QACrB,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC7C,CAAC;IAED,sEAAsE;IACtE,aAAa,CAAC,IAAI,GAAG,IAAI;QACxB,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC;IA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,EAAE,KAAK;SACb,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,cAAc,CAAC,IAAY,EAAE,IAA8B;QAC1D,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,CAAC,aAAa,GAAG,IAAI,CAAC;YACzC,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC;YACnC,IAAI,CAAC,cAAc,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared schema types — column type names, definitions, and the
3
+ * mapping from logical TS types to the Rust ColumnTypeKind.
4
+ */
5
+ export type ColumnType = "string" | "text" | "integer" | "bigInteger" | "decimal" | "boolean" | "date" | "timestamp" | "uuid" | "json" | "binary";
6
+ /** Maps our logical type names to the ColumnTypeKind expected by the Rust compiler. */
7
+ export declare const TYPE_KIND_MAP: Record<ColumnType, string>;
8
+ export interface ColumnDefinition {
9
+ name: string;
10
+ type: ColumnType;
11
+ length?: number;
12
+ precision?: number;
13
+ scale?: number;
14
+ nullable: boolean;
15
+ primary: boolean;
16
+ /** Dialect-appropriate auto-increment / identity column (Lucid `increments`). Implies primary key. */
17
+ autoIncrement?: boolean;
18
+ unique: boolean;
19
+ defaultValue?: string;
20
+ references?: {
21
+ table: string;
22
+ column: string;
23
+ };
24
+ }
25
+ export interface IndexDefinition {
26
+ name: string;
27
+ columns: string[];
28
+ unique: boolean;
29
+ }
30
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,UAAU,GACnB,QAAQ,GACR,MAAM,GACN,SAAS,GACT,YAAY,GACZ,SAAS,GACT,SAAS,GACT,MAAM,GACN,WAAW,GACX,MAAM,GACN,MAAM,GACN,QAAQ,CAAC;AAEZ,uFAAuF;AACvF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAYpD,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,sGAAsG;IACtG,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CAChB"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared schema types — column type names, definitions, and the
3
+ * mapping from logical TS types to the Rust ColumnTypeKind.
4
+ */
5
+ /** Maps our logical type names to the ColumnTypeKind expected by the Rust compiler. */
6
+ export const TYPE_KIND_MAP = {
7
+ string: "string",
8
+ text: "text",
9
+ integer: "integer",
10
+ bigInteger: "bigInteger",
11
+ decimal: "decimal",
12
+ boolean: "boolean",
13
+ date: "date",
14
+ timestamp: "timestamp",
15
+ uuid: "uuid",
16
+ json: "json",
17
+ binary: "binary",
18
+ };
19
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,uFAAuF;AACvF,MAAM,CAAC,MAAM,aAAa,GAA+B;IACxD,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;CAChB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Default `db` singleton — Adonis Lucid–style ergonomic access to the
3
+ * configured database connection.
4
+ *
5
+ * import db from '@c9up/atlas/services/db'
6
+ *
7
+ * const rows = await db.query('SELECT * FROM users WHERE id = ?', [id])
8
+ *
9
+ * Populated by `AtlasProvider.boot()`. The instance is whatever the
10
+ * `database.connections[default]` config block resolves to (typically
11
+ * a `NapiDbAdapter` wrapping the Rust sqlite driver, but apps can
12
+ * swap in a custom `AsyncDatabaseConnection` through the provider's
13
+ * container hooks).
14
+ */
15
+ import type { AsyncDatabaseConnection } from "../adapters/NapiDbAdapter.js";
16
+ /** @internal Bind the singleton (called by AtlasProvider). */
17
+ export declare function setDb(connection: AsyncDatabaseConnection): void;
18
+ /** @internal Read the singleton (or `undefined` pre-boot). */
19
+ export declare function getDb(): AsyncDatabaseConnection | undefined;
20
+ declare const db: AsyncDatabaseConnection;
21
+ export default db;
22
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/services/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAI5E,8DAA8D;AAC9D,wBAAgB,KAAK,CAAC,UAAU,EAAE,uBAAuB,GAAG,IAAI,CAE/D;AAED,8DAA8D;AAC9D,wBAAgB,KAAK,IAAI,uBAAuB,GAAG,SAAS,CAE3D;AAED,QAAA,MAAM,EAAE,EAAE,uBAaR,CAAC;AAEH,eAAe,EAAE,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Default `db` singleton — Adonis Lucid–style ergonomic access to the
3
+ * configured database connection.
4
+ *
5
+ * import db from '@c9up/atlas/services/db'
6
+ *
7
+ * const rows = await db.query('SELECT * FROM users WHERE id = ?', [id])
8
+ *
9
+ * Populated by `AtlasProvider.boot()`. The instance is whatever the
10
+ * `database.connections[default]` config block resolves to (typically
11
+ * a `NapiDbAdapter` wrapping the Rust sqlite driver, but apps can
12
+ * swap in a custom `AsyncDatabaseConnection` through the provider's
13
+ * container hooks).
14
+ */
15
+ let instance;
16
+ /** @internal Bind the singleton (called by AtlasProvider). */
17
+ export function setDb(connection) {
18
+ instance = connection;
19
+ }
20
+ /** @internal Read the singleton (or `undefined` pre-boot). */
21
+ export function getDb() {
22
+ return instance;
23
+ }
24
+ const db = new Proxy({}, {
25
+ get(_target, prop) {
26
+ if (!instance) {
27
+ throw new Error("[atlas] db singleton accessed before AtlasProvider.boot() ran. " +
28
+ "Check that `@c9up/atlas/provider` is listed in your reamrc.ts " +
29
+ "providers and that `config/database.ts` defines at least one " +
30
+ "connection.");
31
+ }
32
+ const value = Reflect.get(instance, prop, instance);
33
+ return typeof value === "function" ? value.bind(instance) : value;
34
+ },
35
+ });
36
+ export default db;
37
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/services/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,IAAI,QAA6C,CAAC;AAElD,8DAA8D;AAC9D,MAAM,UAAU,KAAK,CAAC,UAAmC;IACxD,QAAQ,GAAG,UAAU,CAAC;AACvB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,KAAK;IACpB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,EAAE,GAA4B,IAAI,KAAK,CAAC,EAA6B,EAAE;IAC5E,GAAG,CAAC,OAAO,EAAE,IAAI;QAChB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,iEAAiE;gBAChE,gEAAgE;gBAChE,+DAA+D;gBAC/D,aAAa,CACd,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,EAAE,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Database cleanup utilities for testing.
3
+ *
4
+ * @implements MISS-19
5
+ */
6
+ import type { AsyncDatabaseConnection } from "../adapters/NapiDbAdapter.js";
7
+ /**
8
+ * Wrap a test in a savepoint that is rolled back after.
9
+ */
10
+ export declare function useTransaction(db: AsyncDatabaseConnection): Promise<() => Promise<void>>;
11
+ /**
12
+ * Truncate all user tables (excludes ream_* framework tables and SQLite internals).
13
+ *
14
+ * The SELECT on `sqlite_master` is SQLite-specific introspection and is kept
15
+ * as raw SQL intentionally — it's not a user query. The resulting DELETEs
16
+ * go through the Rust compiler.
17
+ */
18
+ export declare function truncateAll(db: AsyncDatabaseConnection): Promise<void>;
19
+ //# sourceMappingURL=DatabaseCleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseCleanup.d.ts","sourceRoot":"","sources":["../../src/testing/DatabaseCleanup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;GAEG;AACH,wBAAsB,cAAc,CACnC,EAAE,EAAE,uBAAuB,GACzB,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAM9B;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB5E"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Database cleanup utilities for testing.
3
+ *
4
+ * @implements MISS-19
5
+ */
6
+ import { compileStatementNative, getAtlasDialect } from "../query/native.js";
7
+ /**
8
+ * Wrap a test in a savepoint that is rolled back after.
9
+ */
10
+ export async function useTransaction(db) {
11
+ await db.execute("SAVEPOINT test_savepoint");
12
+ return async () => {
13
+ await db.execute("ROLLBACK TO SAVEPOINT test_savepoint");
14
+ await db.execute("RELEASE SAVEPOINT test_savepoint");
15
+ };
16
+ }
17
+ /**
18
+ * Truncate all user tables (excludes ream_* framework tables and SQLite internals).
19
+ *
20
+ * The SELECT on `sqlite_master` is SQLite-specific introspection and is kept
21
+ * as raw SQL intentionally — it's not a user query. The resulting DELETEs
22
+ * go through the Rust compiler.
23
+ */
24
+ export async function truncateAll(db) {
25
+ // SQL LIKE `_` is a single-char wildcard, not a literal underscore, so the
26
+ // `ESCAPE '\'` clause makes `\_` a literal underscore. The exclusion targets
27
+ // names starting with `ream_` (the convention for framework-private tables,
28
+ // including `ream_migrations`) and SQLite's own `sqlite_%` tables.
29
+ const tables = await db.query("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'ream\\_%' ESCAPE '\\' AND name NOT LIKE 'sqlite_%'");
30
+ const dialect = getAtlasDialect();
31
+ for (const row of tables) {
32
+ const name = row.name;
33
+ if (typeof name !== "string")
34
+ continue;
35
+ const compiled = compileStatementNative({ kind: "delete", table: name, wheres: [] }, dialect);
36
+ await db.execute(compiled.statements[0], compiled.params);
37
+ }
38
+ }
39
+ //# sourceMappingURL=DatabaseCleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseCleanup.js","sourceRoot":"","sources":["../../src/testing/DatabaseCleanup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,EAA2B;IAE3B,MAAM,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAC7C,OAAO,KAAK,IAAI,EAAE;QACjB,MAAM,EAAE,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;QACzD,MAAM,EAAE,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAA2B;IAC5D,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,mEAAmE;IACnE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAC5B,yHAAyH,CACzH,CAAC;IACF,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;IAClC,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,SAAS;QACvC,MAAM,QAAQ,GAAG,sBAAsB,CACtC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAC3C,OAAO,CACP,CAAC;QACF,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;AACF,CAAC"}