brepjs 3.0.2 → 4.0.3

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/brepjs.cjs CHANGED
@@ -1109,9 +1109,16 @@ function andThen(result, fn) {
1109
1109
  return result;
1110
1110
  }
1111
1111
  const flatMap = andThen;
1112
+ function formatError(error) {
1113
+ if (typeof error === "object" && error !== null && "kind" in error && "code" in error && "message" in error) {
1114
+ const e = error;
1115
+ return `[${e.kind}] ${e.code}: ${e.message}`;
1116
+ }
1117
+ return String(error);
1118
+ }
1112
1119
  function unwrap(result) {
1113
1120
  if (result.ok) return result.value;
1114
- throw new Error(`Called unwrap() on an Err: ${String(result.error)}`);
1121
+ throw new Error(`Called unwrap() on an Err: ${formatError(result.error)}`);
1115
1122
  }
1116
1123
  function unwrapOr(result, defaultValue) {
1117
1124
  if (result.ok) return result.value;
@@ -1977,8 +1984,9 @@ function deserializeShape(data) {
1977
1984
  return cast(oc.BRepToolsWrapper.Read(data));
1978
1985
  }
1979
1986
  function isShape3DInternal(shape) {
1980
- const name = shape.constructor.name;
1981
- return name === "Shell" || name === "Solid" || name === "CompSolid" || name === "Compound";
1987
+ const shapeTypeRaw = shape.wrapped?.ShapeType?.();
1988
+ const shapeType2 = typeof shapeTypeRaw === "object" && shapeTypeRaw !== null ? shapeTypeRaw.value : shapeTypeRaw;
1989
+ return typeof shapeType2 === "number" && shapeType2 <= 3;
1982
1990
  }
1983
1991
  function buildCompoundOc(shapes) {
1984
1992
  const oc = getKernel().oc;
@@ -2012,9 +2020,29 @@ function fuseAll$2(shapes, { optimisation = "none", simplify: simplify2 = false,
2012
2020
  shapes.map((s) => s.wrapped),
2013
2021
  { optimisation, simplify: simplify2, strategy }
2014
2022
  );
2023
+ const shapeTypeEnumRaw = result.ShapeType?.();
2024
+ const shapeTypeEnum = typeof shapeTypeEnumRaw === "object" && shapeTypeEnumRaw !== null ? shapeTypeEnumRaw.value : shapeTypeEnumRaw;
2025
+ const typeNames = [
2026
+ "COMPOUND",
2027
+ "COMPSOLID",
2028
+ "SOLID",
2029
+ "SHELL",
2030
+ "FACE",
2031
+ "WIRE",
2032
+ "EDGE",
2033
+ "VERTEX",
2034
+ "SHAPE"
2035
+ ];
2036
+ const rawTypeName = typeof shapeTypeEnum === "number" ? typeNames[shapeTypeEnum] ?? `UNKNOWN(${shapeTypeEnum})` : "UNKNOWN";
2015
2037
  return andThen(cast(result), (newShape) => {
2016
- if (!isShape3DInternal(newShape))
2017
- return err(typeCastError("FUSE_ALL_NOT_3D", "fuseAll did not produce a 3D shape"));
2038
+ if (!isShape3DInternal(newShape)) {
2039
+ return err(
2040
+ typeCastError(
2041
+ "FUSE_ALL_NOT_3D",
2042
+ `fuseAll did not produce a 3D shape. Got ${rawTypeName} (${newShape.constructor.name}) instead.`
2043
+ )
2044
+ );
2045
+ }
2018
2046
  return ok(newShape);
2019
2047
  });
2020
2048
  }
@@ -3869,8 +3897,21 @@ function buildCompoundOcInternal(shapes) {
3869
3897
  function castToShape3D(shape, errorCode, errorMsg) {
3870
3898
  const wrapped = castShape(shape);
3871
3899
  if (!isShape3D(wrapped)) {
3900
+ const shapeType2 = shape.ShapeType();
3901
+ const typeNames = [
3902
+ "COMPOUND",
3903
+ "COMPSOLID",
3904
+ "SOLID",
3905
+ "SHELL",
3906
+ "FACE",
3907
+ "WIRE",
3908
+ "EDGE",
3909
+ "VERTEX",
3910
+ "SHAPE"
3911
+ ];
3912
+ const typeName = typeNames[shapeType2] ?? `UNKNOWN(${shapeType2})`;
3872
3913
  wrapped[Symbol.dispose]();
3873
- return err(typeCastError(errorCode, errorMsg));
3914
+ return err(typeCastError(errorCode, `${errorMsg}. Got ${typeName} instead.`));
3874
3915
  }
3875
3916
  return ok(wrapped);
3876
3917
  }
package/dist/brepjs.js CHANGED
@@ -1107,9 +1107,16 @@ function andThen(result, fn) {
1107
1107
  return result;
1108
1108
  }
1109
1109
  const flatMap = andThen;
1110
+ function formatError(error) {
1111
+ if (typeof error === "object" && error !== null && "kind" in error && "code" in error && "message" in error) {
1112
+ const e = error;
1113
+ return `[${e.kind}] ${e.code}: ${e.message}`;
1114
+ }
1115
+ return String(error);
1116
+ }
1110
1117
  function unwrap(result) {
1111
1118
  if (result.ok) return result.value;
1112
- throw new Error(`Called unwrap() on an Err: ${String(result.error)}`);
1119
+ throw new Error(`Called unwrap() on an Err: ${formatError(result.error)}`);
1113
1120
  }
1114
1121
  function unwrapOr(result, defaultValue) {
1115
1122
  if (result.ok) return result.value;
@@ -1975,8 +1982,9 @@ function deserializeShape(data) {
1975
1982
  return cast(oc.BRepToolsWrapper.Read(data));
1976
1983
  }
1977
1984
  function isShape3DInternal(shape) {
1978
- const name = shape.constructor.name;
1979
- return name === "Shell" || name === "Solid" || name === "CompSolid" || name === "Compound";
1985
+ const shapeTypeRaw = shape.wrapped?.ShapeType?.();
1986
+ const shapeType2 = typeof shapeTypeRaw === "object" && shapeTypeRaw !== null ? shapeTypeRaw.value : shapeTypeRaw;
1987
+ return typeof shapeType2 === "number" && shapeType2 <= 3;
1980
1988
  }
1981
1989
  function buildCompoundOc(shapes) {
1982
1990
  const oc = getKernel().oc;
@@ -2010,9 +2018,29 @@ function fuseAll$2(shapes, { optimisation = "none", simplify: simplify2 = false,
2010
2018
  shapes.map((s) => s.wrapped),
2011
2019
  { optimisation, simplify: simplify2, strategy }
2012
2020
  );
2021
+ const shapeTypeEnumRaw = result.ShapeType?.();
2022
+ const shapeTypeEnum = typeof shapeTypeEnumRaw === "object" && shapeTypeEnumRaw !== null ? shapeTypeEnumRaw.value : shapeTypeEnumRaw;
2023
+ const typeNames = [
2024
+ "COMPOUND",
2025
+ "COMPSOLID",
2026
+ "SOLID",
2027
+ "SHELL",
2028
+ "FACE",
2029
+ "WIRE",
2030
+ "EDGE",
2031
+ "VERTEX",
2032
+ "SHAPE"
2033
+ ];
2034
+ const rawTypeName = typeof shapeTypeEnum === "number" ? typeNames[shapeTypeEnum] ?? `UNKNOWN(${shapeTypeEnum})` : "UNKNOWN";
2013
2035
  return andThen(cast(result), (newShape) => {
2014
- if (!isShape3DInternal(newShape))
2015
- return err(typeCastError("FUSE_ALL_NOT_3D", "fuseAll did not produce a 3D shape"));
2036
+ if (!isShape3DInternal(newShape)) {
2037
+ return err(
2038
+ typeCastError(
2039
+ "FUSE_ALL_NOT_3D",
2040
+ `fuseAll did not produce a 3D shape. Got ${rawTypeName} (${newShape.constructor.name}) instead.`
2041
+ )
2042
+ );
2043
+ }
2016
2044
  return ok(newShape);
2017
2045
  });
2018
2046
  }
@@ -3867,8 +3895,21 @@ function buildCompoundOcInternal(shapes) {
3867
3895
  function castToShape3D(shape, errorCode, errorMsg) {
3868
3896
  const wrapped = castShape(shape);
3869
3897
  if (!isShape3D(wrapped)) {
3898
+ const shapeType2 = shape.ShapeType();
3899
+ const typeNames = [
3900
+ "COMPOUND",
3901
+ "COMPSOLID",
3902
+ "SOLID",
3903
+ "SHELL",
3904
+ "FACE",
3905
+ "WIRE",
3906
+ "EDGE",
3907
+ "VERTEX",
3908
+ "SHAPE"
3909
+ ];
3910
+ const typeName = typeNames[shapeType2] ?? `UNKNOWN(${shapeType2})`;
3870
3911
  wrapped[Symbol.dispose]();
3871
- return err(typeCastError(errorCode, errorMsg));
3912
+ return err(typeCastError(errorCode, `${errorMsg}. Got ${typeName} instead.`));
3872
3913
  }
3873
3914
  return ok(wrapped);
3874
3915
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs",
3
- "version": "3.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Web CAD library built on OpenCascade",
5
5
  "keywords": [
6
6
  "cad",