@shop-os/modelkit 0.4.3 → 0.4.4

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/catalog.js CHANGED
@@ -2499,16 +2499,26 @@ var ArraysSchema = z2.record(z2.string().min(1), z2.array(z2.string()).min(1)).s
2499
2499
  }
2500
2500
  }
2501
2501
  });
2502
+ var DimensionsSchema = z2.strictObject({
2503
+ field: z2.string().min(1),
2504
+ areas: z2.record(z2.string(), z2.number().int().positive()).refine((a) => Object.keys(a).length > 0, {
2505
+ message: "inputSpec.dimensions.areas must name at least one size"
2506
+ }),
2507
+ maxSide: z2.number().int().positive().optional(),
2508
+ multipleOf: z2.number().int().positive().optional()
2509
+ });
2502
2510
  var InputSpecSchema = z2.strictObject({
2503
2511
  fields: FieldsSchema,
2504
2512
  values: ValuesSchema.optional(),
2505
2513
  static: StaticSchema.optional(),
2506
2514
  arrays: ArraysSchema.optional(),
2507
- editEndpoint: z2.string().min(1).optional()
2515
+ editEndpoint: z2.string().min(1).optional(),
2516
+ dimensions: DimensionsSchema.optional()
2508
2517
  }).superRefine((spec, ctx) => {
2509
2518
  const mappedNames = /* @__PURE__ */ new Set([
2510
2519
  ...Object.values(spec.fields),
2511
- ...Object.keys(spec.arrays ?? {})
2520
+ ...Object.keys(spec.arrays ?? {}),
2521
+ ...spec.dimensions ? [spec.dimensions.field] : []
2512
2522
  ]);
2513
2523
  for (const key of Object.keys(spec.static ?? {})) {
2514
2524
  if (mappedNames.has(key)) {
@@ -2537,7 +2547,10 @@ function validateInputSpec(raw, row) {
2537
2547
  return {
2538
2548
  ok: false,
2539
2549
  issues: [
2540
- { path: [], message: "inputSpec is only supported on replicate and fal rows" }
2550
+ {
2551
+ path: [],
2552
+ message: "inputSpec is only supported on replicate and fal rows"
2553
+ }
2541
2554
  ]
2542
2555
  };
2543
2556
  }
@@ -2630,6 +2643,29 @@ function validateInputSpec(raw, row) {
2630
2643
  }
2631
2644
  }
2632
2645
  }
2646
+ if (spec.dimensions !== void 0) {
2647
+ if (row.type !== "image") {
2648
+ issues.push({
2649
+ path: ["dimensions"],
2650
+ message: "inputSpec.dimensions is only supported on image rows"
2651
+ });
2652
+ }
2653
+ for (const key of ["aspectRatio", "size"]) {
2654
+ if (key in spec.fields) {
2655
+ issues.push({
2656
+ path: ["fields", key],
2657
+ message: `inputSpec.fields "${key}" cannot be set with inputSpec.dimensions, which sends it`
2658
+ });
2659
+ }
2660
+ }
2661
+ const owner = seenNames.get(spec.dimensions.field);
2662
+ if (owner !== void 0 || spec.dimensions.field in (spec.arrays ?? {})) {
2663
+ issues.push({
2664
+ path: ["dimensions", "field"],
2665
+ message: `inputSpec.dimensions.field "${spec.dimensions.field}" is already a mapped provider field`
2666
+ });
2667
+ }
2668
+ }
2633
2669
  const supports = row.constraints.supports ?? [];
2634
2670
  for (const key of INPUT_SPEC_SUPPORTS_KEYS) {
2635
2671
  if (supports.includes(key)) continue;