@vritti/api-sdk 0.1.0 → 0.1.1

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.cjs CHANGED
@@ -280,10 +280,14 @@ var PrimaryDatabaseService = class _PrimaryDatabaseService {
280
280
  connectionString: databaseUrl,
281
281
  max: this.options.maxConnections || 10
282
282
  });
283
+ this.logger.debug(`Schema keys passed to drizzle: [${Object.keys(this.options.drizzleSchema || {}).join(", ")}]`);
284
+ this.logger.debug(`Relations keys passed to drizzle: [${Object.keys(this.options.drizzleRelations || {}).join(", ")}]`);
283
285
  this.db = (0, import_node_postgres.drizzle)({
284
286
  client: this.pool,
285
- schema: this.options.drizzleSchema
287
+ schema: this.options.drizzleSchema,
288
+ relations: this.options.drizzleRelations
286
289
  });
290
+ this.logger.debug(`Drizzle query keys after init: [${Object.keys(this.db.query || {}).join(", ")}]`);
287
291
  await this.pool.query("SELECT 1");
288
292
  this.logger.log("Connected to primary database (tenant registry)");
289
293
  } catch (error) {
@@ -1326,21 +1330,28 @@ var PrimaryBaseRepository = class {
1326
1330
  return this.database.drizzleClient;
1327
1331
  }
1328
1332
  /**
1329
- * Model query API for THIS repository's table (Prisma-like syntax)
1333
+ * Model query API for THIS repository's table (Drizzle v2 relational queries)
1330
1334
  * Scoped to only the table this repository manages.
1331
1335
  * Returns a type-safe wrapper around Drizzle's RelationalQueryBuilder.
1332
1336
  *
1333
1337
  * @example
1334
1338
  * ```typescript
1335
- * // Use relational queries with type safety
1339
+ * // Use relational queries with v2 object-based where syntax
1336
1340
  * const user = await this.model.findFirst({
1337
- * where: eq(users.id, id),
1341
+ * where: { id },
1338
1342
  * with: { posts: true, profile: true }
1339
1343
  * });
1340
1344
  * ```
1341
1345
  */
1342
1346
  get model() {
1343
- return this.database.drizzleClient.query[this.tableName];
1347
+ const query = this.database.drizzleClient.query;
1348
+ const queryKeys = Object.keys(query || {});
1349
+ this.logger.debug(`Looking for '${this.tableName}' in query keys: [${queryKeys.join(", ")}]`);
1350
+ const model = query[this.tableName];
1351
+ if (!model) {
1352
+ this.logger.error(`Table '${this.tableName}' not found in query object. Available: [${queryKeys.join(", ")}]`);
1353
+ }
1354
+ return model;
1344
1355
  }
1345
1356
  /**
1346
1357
  * Create a new repository instance
@@ -1363,6 +1374,7 @@ var PrimaryBaseRepository = class {
1363
1374
  this.tableName = (0, import_drizzle_orm2.getTableName)(table);
1364
1375
  this.logger = new import_common11.Logger(this.constructor.name);
1365
1376
  this.logger.debug(`Initialized ${this.constructor.name}`);
1377
+ this.logger.debug(`Table name from getTableName: '${this.tableName}'`);
1366
1378
  }
1367
1379
  /**
1368
1380
  * Create a new record
@@ -1396,21 +1408,31 @@ var PrimaryBaseRepository = class {
1396
1408
  */
1397
1409
  async findById(id) {
1398
1410
  this.logger.debug(`Finding record by ID: ${id}`);
1399
- const idColumn = this.table.id;
1400
1411
  return this.model.findFirst({
1401
- where: (0, import_drizzle_orm2.eq)(idColumn, id)
1412
+ where: {
1413
+ id
1414
+ }
1402
1415
  });
1403
1416
  }
1404
1417
  /**
1405
- * Find a single record with custom where clause
1418
+ * Find a single record with custom where clause (Drizzle v2 object-based syntax)
1406
1419
  *
1407
- * @param where - SQL condition
1420
+ * @param where - Object-based filter condition
1408
1421
  * @returns Promise resolving to the record or undefined if not found
1409
1422
  *
1410
1423
  * @example
1411
1424
  * ```typescript
1412
- * import { eq } from 'drizzle-orm';
1413
- * const user = await userRepository.findOne(eq(users.email, 'user@example.com'));
1425
+ * // Simple equality
1426
+ * const user = await userRepository.findOne({ email: 'user@example.com' });
1427
+ *
1428
+ * // With operators
1429
+ * const user = await userRepository.findOne({ age: { gte: 18 } });
1430
+ *
1431
+ * // Multiple conditions (AND)
1432
+ * const user = await userRepository.findOne({
1433
+ * email: 'user@example.com',
1434
+ * status: 'ACTIVE'
1435
+ * });
1414
1436
  * ```
1415
1437
  */
1416
1438
  async findOne(where) {
@@ -1420,25 +1442,33 @@ var PrimaryBaseRepository = class {
1420
1442
  });
1421
1443
  }
1422
1444
  /**
1423
- * Find multiple records
1445
+ * Find multiple records (Drizzle v2 object-based syntax)
1424
1446
  *
1425
1447
  * @param options - Query options (where, orderBy, limit, offset)
1426
1448
  * @returns Promise resolving to an array of records
1427
1449
  *
1428
1450
  * @example
1429
1451
  * ```typescript
1430
- * import { eq, desc } from 'drizzle-orm';
1431
- *
1432
1452
  * // Find all users
1433
1453
  * const users = await userRepository.findMany();
1434
1454
  *
1435
- * // Find with filtering and pagination
1455
+ * // Find with filtering and pagination (v2 object syntax)
1436
1456
  * const users = await userRepository.findMany({
1437
- * where: eq(users.accountStatus, 'ACTIVE'),
1438
- * orderBy: desc(users.createdAt),
1457
+ * where: { accountStatus: 'ACTIVE' },
1458
+ * orderBy: { createdAt: 'desc' },
1439
1459
  * limit: 10,
1440
1460
  * offset: 0
1441
1461
  * });
1462
+ *
1463
+ * // Multiple conditions
1464
+ * const users = await userRepository.findMany({
1465
+ * where: {
1466
+ * AND: [
1467
+ * { status: 'ACTIVE' },
1468
+ * { age: { gte: 18 } }
1469
+ * ]
1470
+ * }
1471
+ * });
1442
1472
  * ```
1443
1473
  */
1444
1474
  async findMany(options) {