@noormdev/sdk 1.0.0-alpha.20 → 1.0.0-alpha.21

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/dist/index.d.ts CHANGED
@@ -2255,6 +2255,39 @@ export interface TableDetail {
2255
2255
  foreignKeys: ForeignKeySummary[];
2256
2256
  rowCountEstimate?: number;
2257
2257
  }
2258
+ /**
2259
+ * Teardown Types
2260
+ *
2261
+ * Types for database reset and teardown operations.
2262
+ * Supports data wipe (truncate) and schema teardown (drop).
2263
+ */
2264
+ /**
2265
+ * Options for truncating table data.
2266
+ *
2267
+ * @example
2268
+ * ```typescript
2269
+ * // Truncate all tables except preserved ones from settings
2270
+ * await truncateData(db, 'postgres', {
2271
+ * preserve: ['AppSettings', 'UserRoles'],
2272
+ * restartIdentity: true,
2273
+ * })
2274
+ *
2275
+ * // Truncate only specific tables
2276
+ * await truncateData(db, 'postgres', {
2277
+ * only: ['users', 'posts'],
2278
+ * })
2279
+ * ```
2280
+ */
2281
+ export interface TruncateOptions {
2282
+ /** Tables to preserve (won't be truncated) */
2283
+ preserve?: string[];
2284
+ /** If set, only truncate these tables (inverse of preserve) */
2285
+ only?: string[];
2286
+ /** Restart identity/auto-increment sequences (default: true) */
2287
+ restartIdentity?: boolean;
2288
+ /** Dry run - return SQL without executing */
2289
+ dryRun?: boolean;
2290
+ }
2258
2291
  /**
2259
2292
  * Result of a truncate operation.
2260
2293
  */
@@ -2357,12 +2390,22 @@ export declare class DbNamespace {
2357
2390
  /**
2358
2391
  * Wipe all data, keeping the schema intact.
2359
2392
  *
2393
+ * User-provided preserve/only options take priority.
2394
+ * Falls back to settings.teardown.preserveTables from settings.yml.
2395
+ *
2360
2396
  * @example
2361
2397
  * ```typescript
2398
+ * // Uses preserve list from settings.yml automatically
2362
2399
  * const result = await ctx.noorm.db.truncate()
2400
+ *
2401
+ * // Override with explicit preserve list
2402
+ * const result = await ctx.noorm.db.truncate({ preserve: ['seeds'] })
2403
+ *
2404
+ * // Truncate only specific tables
2405
+ * const result = await ctx.noorm.db.truncate({ only: ['users', 'posts'] })
2363
2406
  * ```
2364
2407
  */
2365
- truncate(): Promise<TruncateResult>;
2408
+ truncate(options?: TruncateOptions): Promise<TruncateResult>;
2366
2409
  /**
2367
2410
  * Drop all database objects except noorm tracking tables.
2368
2411
  *
package/dist/index.js CHANGED
@@ -23499,14 +23499,28 @@ var DbNamespace = class {
23499
23499
  /**
23500
23500
  * Wipe all data, keeping the schema intact.
23501
23501
  *
23502
+ * User-provided preserve/only options take priority.
23503
+ * Falls back to settings.teardown.preserveTables from settings.yml.
23504
+ *
23502
23505
  * @example
23503
23506
  * ```typescript
23507
+ * // Uses preserve list from settings.yml automatically
23504
23508
  * const result = await ctx.noorm.db.truncate()
23509
+ *
23510
+ * // Override with explicit preserve list
23511
+ * const result = await ctx.noorm.db.truncate({ preserve: ['seeds'] })
23512
+ *
23513
+ * // Truncate only specific tables
23514
+ * const result = await ctx.noorm.db.truncate({ only: ['users', 'posts'] })
23505
23515
  * ```
23506
23516
  */
23507
- async truncate() {
23517
+ async truncate(options) {
23508
23518
  checkProtectedConfig(this.#state.config, "truncate", this.#state.options);
23509
- return truncateData(this.#kysely, this.#dialect);
23519
+ const preserve = options?.preserve ?? this.#state.settings.teardown?.preserveTables;
23520
+ return truncateData(this.#kysely, this.#dialect, {
23521
+ ...options,
23522
+ preserve
23523
+ });
23510
23524
  }
23511
23525
  /**
23512
23526
  * Drop all database objects except noorm tracking tables.
@@ -23520,7 +23534,9 @@ var DbNamespace = class {
23520
23534
  checkProtectedConfig(this.#state.config, "teardown", this.#state.options);
23521
23535
  return teardownSchema(this.#kysely, this.#dialect, {
23522
23536
  configName: this.#state.config.name,
23523
- executedBy: formatIdentity(this.#state.identity)
23537
+ executedBy: formatIdentity(this.#state.identity),
23538
+ preserveTables: this.#state.settings.teardown?.preserveTables,
23539
+ postScript: this.#state.settings.teardown?.postScript
23524
23540
  });
23525
23541
  }
23526
23542
  /**