@zeyolabs/shopping 2026.11.56 → 2026.11.57

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.
@@ -1,32 +1,38 @@
1
- import { asc, inArray } from 'drizzle-orm';
1
+ import { inArray, sql } from 'drizzle-orm';
2
2
 
3
3
  import type { ShopDb } from '../db/index';
4
4
 
5
- import { productImages } from '../db/schema';
5
+ import { products } from '../db/schema';
6
6
  import { Batches } from '../utils/batches';
7
7
 
8
8
  export type Cover = { alt: string; src: string };
9
9
 
10
+ /** One column of a product's lowest-position photo: one index lookup per product, not every photo. */
11
+ function firstPhoto(column: 'alt' | 'src') {
12
+ return sql<
13
+ null | string
14
+ >`(select pi.${sql.raw(column)} from product_images pi where pi.product_id = "products"."id" order by pi.position limit 1)`;
15
+ }
16
+
10
17
  /** Each product's cover image: its lowest-position photo. */
11
18
  export class CoverService {
12
19
  constructor(private readonly db: ShopDb) {}
13
20
 
14
21
  /** Cover per product id; products without photos are left out. */
15
22
  async covers(productIds: readonly number[]): Promise<Map<number, Cover>> {
16
- const images = await Batches.rows(productIds, (slice) =>
23
+ const rows = await Batches.rows(productIds, (slice) =>
17
24
  this.db
18
25
  .select({
19
- alt: productImages.alt,
20
- productId: productImages.productId,
21
- src: productImages.src,
26
+ alt: firstPhoto('alt'),
27
+ productId: products.id,
28
+ src: firstPhoto('src'),
22
29
  })
23
- .from(productImages)
24
- .where(inArray(productImages.productId, slice))
25
- .orderBy(asc(productImages.position))
30
+ .from(products)
31
+ .where(inArray(products.id, slice))
26
32
  );
27
33
  const covers = new Map<number, Cover>();
28
- for (const { productId, ...image } of images) {
29
- if (!covers.has(productId)) covers.set(productId, image);
34
+ for (const { alt, productId, src } of rows) {
35
+ if (src !== null) covers.set(productId, { alt: alt ?? '', src });
30
36
  }
31
37
  return covers;
32
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeyolabs/shopping",
3
- "version": "2026.11.56",
3
+ "version": "2026.11.57",
4
4
  "description": "Shop and order fulfilment for SvelteKit 3 on Cloudflare: catalogue, basket, Stripe Checkout, orders, Royal Mail Click & Drop, order emails, packing, pages and admin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",